-
-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: loader's tests for errors and warnings (#1736)
* tests: loader's error regression test for #1581 * tests: add test on error code * tests: add tests in case of warnings from loader Co-authored-by: Anshuman Verma <[email protected]>
- Loading branch information
Showing
10 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,4 @@ packages/**/*.map | |
|
||
# temporary test files | ||
test-assets/ | ||
./lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
// eslint-disable-next-line node/no-unpublished-require | ||
const { run } = require('../../utils/test-utils'); | ||
|
||
describe('loader error regression test for #1581', () => { | ||
it(`should not ignore loader's error produce a failing build`, () => { | ||
// Ignoring assertion on stderr because ts-loader is producing depreciation warnings | ||
// with webpack@v5.0.0-beta.24 -> https://github.com/TypeStrong/ts-loader/issues/1169 | ||
const { stdout, exitCode } = run(__dirname, [], false); | ||
expect(exitCode).not.toEqual(0); | ||
expect(stdout).toContain('[1 error]'); | ||
expect(stdout).toContain(`Cannot assign to 'foobar' because it is a constant`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"dependencies": { | ||
"ts-loader": "^7.0.5", | ||
"typescript": "^3.9.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const foobar = 'foobar'; | ||
// eslint-disable-next-line no-const-assign | ||
foobar = 'barbaz'; // Error! | ||
console.log(foobar); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
mode: 'development', | ||
|
||
entry: { | ||
bundle: './src/index.ts', | ||
}, | ||
|
||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: '[name].js', | ||
}, | ||
|
||
module: { | ||
rules: [ | ||
{ | ||
test: /.(ts|tsx)?$/, | ||
loader: 'ts-loader', | ||
include: [path.resolve(__dirname, 'src')], | ||
exclude: [/node_modules/], | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
const { run } = require('../../utils/test-utils'); | ||
|
||
describe('loader warning test', () => { | ||
it(`should not ignore loader's warning and exit with a non zero exit code`, () => { | ||
const { stdout, exitCode } = run(__dirname, [], false); | ||
|
||
expect(stdout).toContain('[1 warning]'); | ||
expect(stdout).toContain('This is a warning'); | ||
expect(exitCode).not.toEqual(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = function loader(source) { | ||
const { emitWarning } = this; | ||
emitWarning('This is a warning'); | ||
return source; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('../my-loader'); | ||
console.log('loader warning test'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
mode: 'development', | ||
|
||
entry: { | ||
bundle: './src/main.js', | ||
}, | ||
|
||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: '[name].js', | ||
}, | ||
|
||
module: { | ||
rules: [ | ||
{ | ||
test: /.(js|jsx)?$/, | ||
loader: 'my-loader', | ||
include: [path.resolve(__dirname, 'src')], | ||
exclude: [/node_modules/], | ||
}, | ||
], | ||
}, | ||
resolveLoader: { | ||
alias: { | ||
'my-loader': require.resolve('./my-loader'), | ||
}, | ||
}, | ||
}; |