Skip to content

Commit

Permalink
test: add some tests for the pkg: import feature
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Feb 17, 2024
1 parent c6a5e1d commit 630b220
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ npm-debug.log*
node_modules/
!fixtures/e2e/node_modules
!fixtures/e2e/completion/node_modules
!fixtures/pkg-import/node_modules
!fixtures/e2e/pkg-import/node_modules

# Compiled and temporary files
dist/
Expand Down
19 changes: 19 additions & 0 deletions e2e/src/suite/definition/definitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ describe("SCSS Definition Test", function () {
const vueDocUri = getDocUri("definition/AppButton.vue");
const svelteDocUri = getDocUri("definition/AppButton.svelte");
const astroDocUri = getDocUri("definition/AppButton.astro");
const pkgImportUri = getDocUri("pkg-import/src/styles.scss");
const scopedPkgImportUri = getDocUri("pkg-import/src/scoped.scss");

before(async () => {
await showFile(docUri);
await showFile(vueDocUri);
await showFile(svelteDocUri);
await showFile(astroDocUri);
await showFile(pkgImportUri);
await sleepCI();
});

Expand Down Expand Up @@ -77,4 +80,20 @@ describe("SCSS Definition Test", function () {
await testDefinition(svelteDocUri, position(18, 17), expectedLocation);
await testDefinition(astroDocUri, position(21, 17), expectedLocation);
});

it("finds symbol from pkg: import", async () => {
const expectedDocumentUri = getDocUri(
"pkg-import/node_modules/my-components/styles/colors.scss",
);
const expectedLocation = sameLineLocation(expectedDocumentUri, 3, 1, 15);
await testDefinition(pkgImportUri, position(4, 19), expectedLocation);
});

it("finds symbol from scoped pkg: import", async () => {
const expectedDocumentUri = getDocUri(
"pkg-import/node_modules/@my-scope/my-components/styles/colors.scss",
);
const expectedLocation = sameLineLocation(expectedDocumentUri, 3, 1, 15);
await testDefinition(scopedPkgImportUri, position(4, 19), expectedLocation);
});
});
9 changes: 9 additions & 0 deletions e2e/src/suite/hover/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ describe("SCSS Hover Test", function () {
const vueDocUri = getDocUri("hover/AppButton.vue");
const svelteDocUri = getDocUri("hover/AppButton.svelte");
const astroDocUri = getDocUri("hover/AppButton.astro");
const pkgImportUri = getDocUri("pkg-import/src/styles.scss");

before(async () => {
await showFile(docUri);
await showFile(collisionUri);
await showFile(vueDocUri);
await showFile(svelteDocUri);
await showFile(astroDocUri);
await showFile(pkgImportUri);
await sleepCI();
});

Expand Down Expand Up @@ -129,4 +131,11 @@ describe("SCSS Hover Test", function () {

await testHover(collisionUri, position(5, 20), expectedContents);
});

it("shows hover for symbols from pkg: import", async () => {
const expectedContents = {
contents: ["Primary brand color"],
};
await testHover(pkgImportUri, position(4, 19), expectedContents);
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions fixtures/e2e/pkg-import/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "pkg-import",
"version": "1.0.0",
"private": true,
"type": "commonjs",
"description": "Test using the pgk import from a module",
"scripts": {
"test": "node --test sass.test.js"
},
"devDependencies": {
"sass": "^1.71.0"
}
}
20 changes: 20 additions & 0 deletions fixtures/e2e/pkg-import/sass.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const assert = require("node:assert");
const { test } = require("node:test");
const sass = require("sass");

test("noscope", () => {
const css = sass.compile("src/styles.scss", {
importers: [new sass.NodePackageImporter()],
});
assert.ok(css);
assert.match(css.css, /color: green/);
});

test("scope", () => {
const css = sass.compile("src/scoped.scss", {
importers: [new sass.NodePackageImporter()],
});
assert.ok(css);
assert.match(css.css, /color: green/);
});
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions fixtures/pkg-import/package.json

This file was deleted.

20 changes: 0 additions & 20 deletions fixtures/pkg-import/sass.test.js

This file was deleted.

0 comments on commit 630b220

Please sign in to comment.