From 83149e8b78cbe4c0f1c68e1a2b38105ebfb2af97 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Wed, 1 Aug 2018 15:21:40 +0200 Subject: [PATCH] test: Refactor module import tests In preparation for https://github.com/webpack-contrib/sass-loader/pull/573 Imports without file extensions are deprecated in LibSass and even not supported in DartSass. --- test/index.test.js | 2 +- test/node_modules/another/package.json | 3 +++ test/node_modules/{module => module/module.scss} | 0 test/node_modules/module/package.json | 3 +++ test/node_modules/other-module | 3 --- test/sass/imports.sass | 5 +++-- test/scss/imports.scss | 6 ++---- test/tools/createSpec.js | 4 ++++ 8 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 test/node_modules/another/package.json rename test/node_modules/{module => module/module.scss} (100%) create mode 100644 test/node_modules/module/package.json delete mode 100644 test/node_modules/other-module diff --git a/test/index.test.js b/test/index.test.js index a0cf7bd6..1826b70f 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -205,7 +205,7 @@ describe("sass-loader", () => { sourceMap.should.not.have.property("file"); sourceMap.should.have.property("sourceRoot", fakeCwd); // This number needs to be updated if imports.scss or any dependency of that changes - sourceMap.sources.should.have.length(13); + sourceMap.sources.should.have.length(12); sourceMap.sources.forEach(sourcePath => fs.existsSync(path.resolve(sourceMap.sourceRoot, sourcePath)) ); diff --git a/test/node_modules/another/package.json b/test/node_modules/another/package.json new file mode 100644 index 00000000..cbd070ab --- /dev/null +++ b/test/node_modules/another/package.json @@ -0,0 +1,3 @@ +{ + "main": "./module.scss" +} diff --git a/test/node_modules/module b/test/node_modules/module/module.scss similarity index 100% rename from test/node_modules/module rename to test/node_modules/module/module.scss diff --git a/test/node_modules/module/package.json b/test/node_modules/module/package.json new file mode 100644 index 00000000..cbd070ab --- /dev/null +++ b/test/node_modules/module/package.json @@ -0,0 +1,3 @@ +{ + "main": "./module.scss" +} diff --git a/test/node_modules/other-module b/test/node_modules/other-module deleted file mode 100644 index 1efaed0b..00000000 --- a/test/node_modules/other-module +++ /dev/null @@ -1,3 +0,0 @@ -.other-module { - background: hotpink; -} diff --git a/test/sass/imports.sass b/test/sass/imports.sass index fc93a369..2fb9b4fc 100644 --- a/test/sass/imports.sass +++ b/test/sass/imports.sass @@ -18,11 +18,12 @@ /* scoped import @import language */ .scoped-imporr @import language + // The local util file should take precedence over Node's util module // See https://github.com/webpack-contrib/sass-loader/issues/556 /* @import util */ @import util /* @import ~module */ @import ~module -/* @import ~other-module */ -@import ~other-module +/* @import ~another */ +@import ~another diff --git a/test/scss/imports.scss b/test/scss/imports.scss index bd6736c9..8de13d79 100644 --- a/test/scss/imports.scss +++ b/test/scss/imports.scss @@ -1,7 +1,5 @@ /* @import "another/module"; */ @import "another/module"; -/* @import "~another/module"; */ -@import "~another/module"; /* @import "another/underscore"; */ @import "another/underscore"; /* @import "another/_underscore"; */ @@ -27,5 +25,5 @@ @import "util"; /* @import "~module"; */ @import "~module"; -/* @import "~other-module"; */ -@import "~other-module"; +/* @import "~another"; */ +@import "~another"; diff --git a/test/tools/createSpec.js b/test/tools/createSpec.js index 84a95a53..dcb20edb 100644 --- a/test/tools/createSpec.js +++ b/test/tools/createSpec.js @@ -15,6 +15,8 @@ function createSpec(ext) { const testNodeModules = path.relative(basePath, path.join(testFolder, "node_modules")) + path.sep; const pathToBootstrap = path.relative(basePath, path.resolve(testFolder, "..", "node_modules", "bootstrap-sass")); const pathToScopedNpmPkg = path.relative(basePath, path.resolve(testFolder, "node_modules", "@org", "pkg", "./index.scss")); + const pathToModule = path.relative(basePath, path.resolve(testFolder, "node_modules", "module", "module.scss")); + const pathToAnother = path.relative(basePath, path.resolve(testFolder, "node_modules", "another", "module.scss")); const pathToFooAlias = path.relative(basePath, path.resolve(testFolder, ext, "another", "alias." + ext)); fs.readdirSync(path.join(testFolder, ext)) @@ -33,6 +35,8 @@ function createSpec(ext) { url = url .replace(/^~bootstrap-sass/, pathToBootstrap) .replace(/^~@org\/pkg/, pathToScopedNpmPkg) + .replace(/^~module/, pathToModule) + .replace(/^~another/, pathToAnother) .replace(/^~/, testNodeModules) .replace(/^path-to-alias/, pathToFooAlias); }