Skip to content

Commit

Permalink
test: webpack resolver (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito committed Sep 11, 2020
1 parent 19eec2a commit a5bebfc
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 31 deletions.
28 changes: 25 additions & 3 deletions test/__snapshots__/loader.test.js.snap
Expand Up @@ -83,8 +83,30 @@ exports[`loader imports files listed in option argument and paths deps: errors 1

exports[`loader imports files listed in option argument and paths deps: warnings 1`] = `Array []`;

exports[`loader imports files listed in option argument and webpack alias: css 1`] = `
".webpack-alias-1 {
color: #f00;
}
.webpack-alias-2 {
color: #ff7f50;
}
body {
font: 12px Helvetica, Arial, sans-serif;
}
a.button {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
"
`;

exports[`loader imports files listed in option argument and webpack alias: errors 1`] = `Array []`;

exports[`loader imports files listed in option argument and webpack alias: warnings 1`] = `Array []`;

exports[`loader imports files listed in option argument and webpack deps: css 1`] = `
".other {
".imported-in-web-modules {
font-size: 2em;
}
body {
Expand Down Expand Up @@ -181,7 +203,7 @@ exports[`loader in a nested import load module from paths: errors 1`] = `Array [
exports[`loader in a nested import load module from paths: warnings 1`] = `Array []`;

exports[`loader in a nested import load module from webpack: css 1`] = `
".other {
".imported-in-web-modules {
font-size: 2em;
}
"
Expand All @@ -201,7 +223,7 @@ exports[`loader in a nested import resolve css with webpack but not import: erro
exports[`loader in a nested import resolve css with webpack but not import: warnings 1`] = `Array []`;

exports[`loader resolve with webpack if stylus can't find it: css 1`] = `
".other {
".imported-in-web-modules {
font-size: 2em;
}
"
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/alias/1.styl
@@ -0,0 +1,2 @@
.webpack-alias-1
color: red
2 changes: 2 additions & 0 deletions test/fixtures/alias/2.styl
@@ -0,0 +1,2 @@
.webpack-alias-2
color: coral
2 changes: 2 additions & 0 deletions test/fixtures/import-webpack-alias.styl
@@ -0,0 +1,2 @@
@import 'alias/1'
@import '~alias/2'
4 changes: 2 additions & 2 deletions test/fixtures/web_modules/in-web-modules/index.styl
@@ -1,2 +1,2 @@
.other
font-size 2em
.imported-in-web-modules
font-size 2em
12 changes: 0 additions & 12 deletions test/helpers/getCompiler.js
Expand Up @@ -34,18 +34,6 @@ export default (fixture, loaderOptions = {}, config = {}) => {
plugins: [],
resolve: {
extensions: ['.js', '.css', '.styl'],
modules: [
'node_modules',
path.join(__dirname, '../', 'fixtures', 'web_modules'),
],
alias: {
'~in-web-modules': path.join(
__dirname,
'../',
'fixtures',
'web_modules'
),
},
},
...config,
};
Expand Down
93 changes: 79 additions & 14 deletions test/loader.test.js
Expand Up @@ -141,7 +141,15 @@ describe('loader', () => {

it("resolve with webpack if stylus can't find it", async () => {
const testId = './import-webpack.styl';
const compiler = getCompiler(testId);
const compiler = getCompiler(
testId,
{},
{
resolve: {
modules: [path.join(__dirname, 'fixtures', 'web_modules')],
},
}
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);

Expand Down Expand Up @@ -178,7 +186,15 @@ describe('loader', () => {

it('in a nested import load module from webpack', async () => {
const testId = './shallow-webpack.styl';
const compiler = getCompiler(testId);
const compiler = getCompiler(
testId,
{},
{
resolve: {
modules: [path.join(__dirname, 'fixtures', 'web_modules')],
},
}
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);

Expand Down Expand Up @@ -397,11 +413,19 @@ describe('loader', () => {

it('imports files listed in option argument webpack style', async () => {
const testId = './stylus.styl';
const compiler = getCompiler(testId, {
stylusOptions: {
import: ['~fakenib'],
const compiler = getCompiler(
testId,
{
stylusOptions: {
import: ['~fakenib'],
},
},
});
{
resolve: {
modules: ['node_modules'],
},
}
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);

Expand All @@ -412,11 +436,19 @@ describe('loader', () => {

it('imports files listed in option "style" package.json', async () => {
const testId = './stylus.styl';
const compiler = getCompiler(testId, {
stylusOptions: {
import: ['~fakestylus'],
const compiler = getCompiler(
testId,
{
stylusOptions: {
import: ['~fakestylus'],
},
},
});
{
resolve: {
modules: ['node_modules'],
},
}
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);

Expand Down Expand Up @@ -458,11 +490,44 @@ describe('loader', () => {

it('imports files listed in option argument and webpack deps', async () => {
const testId = './basic.styl';
const compiler = getCompiler(testId, {
stylusOptions: {
import: ['import-webpack.styl'],
const compiler = getCompiler(
testId,
{
stylusOptions: {
import: ['import-webpack.styl'],
},
},
});
{
resolve: {
modules: [path.join(__dirname, 'fixtures', 'web_modules')],
},
}
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);

expect(codeFromBundle.css).toMatchSnapshot('css');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('imports files listed in option argument and webpack alias', async () => {
const testId = './basic.styl';
const compiler = getCompiler(
testId,
{
stylusOptions: {
import: ['import-webpack-alias.styl'],
},
},
{
resolve: {
alias: {
alias: path.resolve(__dirname, 'fixtures', 'alias'),
},
},
}
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);

Expand Down

0 comments on commit a5bebfc

Please sign in to comment.