Skip to content

Commit d2c2697

Browse files
committed
test: update jest config and refactor loader test
1 parent fc64f12 commit d2c2697

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

__tests__/loader.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import path, { join, dirname, resolve } from 'path'
1+
import path from 'path'
22
import { fileURLToPath } from 'url'
33

44
import webpack from 'webpack'
55
import { createFsFromVolume, Volume } from 'memfs'
66

77
import { debugCode } from '../src/purge.js'
88

9+
const { dirname, resolve } = path
910
const filename = fileURLToPath(import.meta.url)
1011
const directory = dirname(filename)
1112
const build = entry => {
@@ -20,28 +21,28 @@ const build = entry => {
2021
rules: [
2122
{
2223
test: /\.js$/,
23-
use: {
24-
loader: resolve(directory, '../src/loader.js')
25-
}
24+
exclude: /node_modules/,
25+
type: 'module',
26+
loader: resolve(directory, '../src/loader.js')
2627
}
2728
]
2829
}
2930
})
3031

32+
compiler.outputFileSystem.join = path.join.bind(path)
3133
compiler.outputFileSystem = createFsFromVolume(new Volume())
32-
compiler.outputFileSystem.join = join.bind(path)
3334

3435
return new Promise((resolve, reject) => {
3536
compiler.run((err, stats) => {
3637
if (err) {
37-
reject(err)
38+
return reject(err)
3839
}
3940

4041
if (stats.hasErrors()) {
41-
reject(stats.toJson().errors)
42+
return reject(stats.toJson().errors)
4243
}
4344

44-
resolve(stats)
45+
return resolve(stats)
4546
})
4647
})
4748
}

jest.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ export default {
44
coverageReporters: ['json', 'lcov', 'text', 'clover', 'text-summary'],
55
testMatch: [
66
'**/__tests__/**/*.js',
7-
// Has to wait for better ESM support from webpack
7+
/**
8+
* Has to wait for better ESM suport for webpack loaders
9+
* @see https://github.com/webpack/loader-runner/issues/61
10+
*/
811
'!**/__tests__/loader.js',
912
/**
1013
* Has to wait for better support for mocks when using ESM

0 commit comments

Comments
 (0)