Skip to content

Commit

Permalink
test: resolve modules (#1102)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito committed Jul 7, 2020
1 parent edf5347 commit f9b8ef9
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 0 deletions.
110 changes: 110 additions & 0 deletions test/__snapshots__/modules-option.test.js.snap
Expand Up @@ -1042,6 +1042,116 @@ Array [
exports[`"modules" option should should work with two leading underscore: warnings 1`] = `Array []`;
exports[`"modules" option should support resolving in composes preprocessor files with extensions: errors 1`] = `Array []`;
exports[`"modules" option should support resolving in composes preprocessor files with extensions: module 1`] = `
"// Imports
var ___CSS_LOADER_API_IMPORT___ = require(\\"../../../../src/runtime/api.js\\");
var ___CSS_LOADER_ICSS_IMPORT_0___ = require(\\"-!../../../../src/index.js??[ident]!./values.css\\");
var ___CSS_LOADER_ICSS_IMPORT_1___ = require(\\"-!../../../../src/index.js??[ident]!./less-file.less\\");
var ___CSS_LOADER_ICSS_IMPORT_2___ = require(\\"-!../../../../src/index.js??[ident]!./scss-file.scss\\");
var ___CSS_LOADER_ICSS_IMPORT_3___ = require(\\"-!../../../../src/index.js??[ident]!./sass-file.sass\\");
exports = ___CSS_LOADER_API_IMPORT___(false);
exports.i(___CSS_LOADER_ICSS_IMPORT_0___, \\"\\", true);
exports.i(___CSS_LOADER_ICSS_IMPORT_1___, \\"\\", true);
exports.i(___CSS_LOADER_ICSS_IMPORT_2___, \\"\\", true);
exports.i(___CSS_LOADER_ICSS_IMPORT_3___, \\"\\", true);
// Module
exports.push([module.id, \\".globalClassName {\\\\n color: orange;\\\\n}\\\\n\\\\n._2vZioV5tEV-AlqaI8c_mtN {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"v-def\\"] + \\";\\\\n}\\\\n\\\\n.YX1POP6L7ESwR7pdtyRna {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"v-foo\\"] + \\";\\\\n}\\\\n\\\\n._1578mz8iEiOG2qNa19R11c {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_2___.locals[\\"v-bar\\"] + \\";\\\\n}\\\\n\\\\n._1yWiOyfH6HuDl7TOzpnWkK {\\\\n color: \\" + ___CSS_LOADER_ICSS_IMPORT_3___.locals[\\"v-baz\\"] + \\";\\\\n}\\\\n\\\\n.OVj95yO5B9JEdIo3xDMtO {\\\\n background: #000;\\\\n}\\\\n\\", \\"\\"]);
// Exports
exports.locals = {
\\"v-def\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_0___.locals[\\"v-def\\"] + \\"\\",
\\"v-foo\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"v-foo\\"] + \\"\\",
\\"v-bar\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_2___.locals[\\"v-bar\\"] + \\"\\",
\\"v-baz\\": \\"\\" + ___CSS_LOADER_ICSS_IMPORT_3___.locals[\\"v-baz\\"] + \\"\\",
\\"globalClassName\\": \\"globalClassName\\",
\\"ghi\\": \\"_2vZioV5tEV-AlqaI8c_mtN\\",
\\"class\\": \\"YX1POP6L7ESwR7pdtyRna \\" + ___CSS_LOADER_ICSS_IMPORT_1___.locals[\\"lessClass\\"] + \\"\\",
\\"other\\": \\"_1578mz8iEiOG2qNa19R11c \\" + ___CSS_LOADER_ICSS_IMPORT_2___.locals[\\"scssClass\\"] + \\"\\",
\\"last\\": \\"_1yWiOyfH6HuDl7TOzpnWkK \\" + ___CSS_LOADER_ICSS_IMPORT_3___.locals[\\"sassClass\\"] + \\"\\",
\\"otherClassName\\": \\"OVj95yO5B9JEdIo3xDMtO globalClassName\\"
};
module.exports = exports;
"
`;
exports[`"modules" option should support resolving in composes preprocessor files with extensions: result 1`] = `
Array [
Array [
"../../src/index.js?[ident]!./modules/composes/values.css",
"
",
"",
],
Array [
"../../src/index.js?[ident]!./modules/composes/less-file.less",
"._3lZeyjNxPePITWh1xVieTf {
padding: 5px;
}
",
"",
],
Array [
"../../src/index.js?[ident]!./modules/composes/scss-file.scss",
"._228B9eI0iy8oD-AJowJJdF {
padding: 15px;
}
",
"",
],
Array [
"../../src/index.js?[ident]!./modules/composes/sass-file.sass",
"
",
"",
],
Array [
"./modules/composes/composes-preprocessors.css",
".globalClassName {
color: orange;
}
._2vZioV5tEV-AlqaI8c_mtN {
color: red;
}
.YX1POP6L7ESwR7pdtyRna {
color: green;
}
._1578mz8iEiOG2qNa19R11c {
color: white;
}
._1yWiOyfH6HuDl7TOzpnWkK {
color: undefined;
}
.OVj95yO5B9JEdIo3xDMtO {
background: #000;
}
",
"",
],
]
`;
exports[`"modules" option should support resolving in composes preprocessor files with extensions: warnings 1`] = `
Array [
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
Invalid value definition: v-def: red
@value v-foo: green
@value v-bar: white
@value v-baz: coral
.sassClass
padding: 10px",
]
`;
exports[`"modules" option should support resolving in composes: errors 1`] = `Array []`;
exports[`"modules" option should support resolving in composes: module 1`] = `
Expand Down
32 changes: 32 additions & 0 deletions test/fixtures/modules/composes/composes-preprocessors.css
@@ -0,0 +1,32 @@
@value v-def from './values.css';
@value v-foo from './less-file.less';
@value v-bar from './scss-file.scss';
@value v-baz from './sass-file.sass';

:global(.globalClassName) {
color: orange;
}

.ghi {
color: v-def;
}

.class {
color: v-foo;
composes: lessClass from "less-file.less";
}

.other {
color: v-bar;
composes: scssClass from "scss-file.scss";
}

.last {
color: v-baz;
composes: sassClass from "sass-file.sass";
}

.otherClassName {
composes: globalClassName from global;
background: #000;
}
5 changes: 5 additions & 0 deletions test/fixtures/modules/composes/composes-preprocessors.js
@@ -0,0 +1,5 @@
import css from './composes-preprocessors.css';

__export__ = css;

export default css;
8 changes: 8 additions & 0 deletions test/fixtures/modules/composes/less-file.less
@@ -0,0 +1,8 @@
@value v-def: red;
@value v-foo: green;
@value v-bar: white;
@value v-baz: coral;

.lessClass {
padding: 5px;
}
8 changes: 8 additions & 0 deletions test/fixtures/modules/composes/sass-file.sass
@@ -0,0 +1,8 @@
@value v-def: red
@value v-foo: green
@value v-bar: white
@value v-baz: coral

.sassClass
padding: 10px

8 changes: 8 additions & 0 deletions test/fixtures/modules/composes/scss-file.scss
@@ -0,0 +1,8 @@
@value v-def: red;
@value v-foo: green;
@value v-bar: white;
@value v-baz: coral;

.scssClass {
padding: 15px;
}
22 changes: 22 additions & 0 deletions test/modules-option.test.js
Expand Up @@ -328,6 +328,28 @@ describe('"modules" option', () => {
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('should support resolving in composes preprocessor files with extensions', async () => {
const compiler = getCompiler(
'./modules/composes/composes-preprocessors.js',
{
modules: {
mode: 'local',
exportGlobals: true,
},
}
);
const stats = await compile(compiler);

expect(
getModuleSource('./modules/composes/composes-preprocessors.css', stats)
).toMatchSnapshot('module');
expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot(
'result'
);
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('issue #286', async () => {
const compiler = getCompiler(
'./modules/issue-286/source.js',
Expand Down

0 comments on commit f9b8ef9

Please sign in to comment.