Skip to content

Commit

Permalink
test: Refactor module import tests
Browse files Browse the repository at this point in the history
In preparation for #573
Imports without file extensions are deprecated in LibSass and
even not supported in DartSass.
  • Loading branch information
jhnns committed Aug 1, 2018
1 parent d0b35cb commit 83149e8
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test/index.test.js
Expand Up @@ -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))
);
Expand Down
3 changes: 3 additions & 0 deletions test/node_modules/another/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
3 changes: 3 additions & 0 deletions test/node_modules/module/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions test/node_modules/other-module

This file was deleted.

5 changes: 3 additions & 2 deletions test/sass/imports.sass
Expand Up @@ -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
6 changes: 2 additions & 4 deletions 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"; */
Expand All @@ -27,5 +25,5 @@
@import "util";
/* @import "~module"; */
@import "~module";
/* @import "~other-module"; */
@import "~other-module";
/* @import "~another"; */
@import "~another";
4 changes: 4 additions & 0 deletions test/tools/createSpec.js
Expand Up @@ -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))
Expand All @@ -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);
}
Expand Down

0 comments on commit 83149e8

Please sign in to comment.