Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit b79b24a

Browse files
committed
fix: fix hardcoded value
1 parent 904553a commit b79b24a

File tree

4 files changed

+99
-7
lines changed

4 files changed

+99
-7
lines changed

src/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { interpolateName } = require("loader-utils");
22

33
const schema = require("./options.json");
44

5-
function loader(content) {
5+
export default function loader(content) {
66
const { rootContext, _compiler, getOptions, emitFile } = this;
77
const options = getOptions(schema);
88
const { flags } = options;
@@ -28,5 +28,4 @@ try {
2828
`;
2929
}
3030

31-
module.exports = loader;
32-
module.exports.raw = true;
31+
export const raw = true;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`loader should throw an error on broken "node" addon: errors 1`] = `
4+
Array [
5+
"ModuleBuildError: Module build failed (from ../../src/index.js):
6+
ValidationError: Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.",
7+
]
8+
`;
9+
10+
exports[`loader should throw an error on broken "node" addon: module 1`] = `undefined`;
11+
12+
exports[`loader should throw an error on broken "node" addon: warnings 1`] = `Array []`;
13+
14+
exports[`loader should work: module 1`] = `undefined`;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`validate options should throw an error on the "flags" option with "false" value 1`] = `
4+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
5+
- options.flags should be an integer.
6+
-> An integer value that allows to specify dlopen behavior.
7+
-> Read more at https://github.com/webpack-contrib/node-loader#flags"
8+
`;
9+
10+
exports[`validate options should throw an error on the "flags" option with "test" value 1`] = `
11+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
12+
- options.flags should be an integer.
13+
-> An integer value that allows to specify dlopen behavior.
14+
-> Read more at https://github.com/webpack-contrib/node-loader#flags"
15+
`;
16+
17+
exports[`validate options should throw an error on the "flags" option with "true" value 1`] = `
18+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
19+
- options.flags should be an integer.
20+
-> An integer value that allows to specify dlopen behavior.
21+
-> Read more at https://github.com/webpack-contrib/node-loader#flags"
22+
`;
23+
24+
exports[`validate options should throw an error on the "name" option with "false" value 1`] = `
25+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
26+
- options has an unknown property 'name'. These properties are valid:
27+
object { flags? }"
28+
`;
29+
30+
exports[`validate options should throw an error on the "name" option with "true" value 1`] = `
31+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
32+
- options has an unknown property 'name'. These properties are valid:
33+
object { flags? }"
34+
`;
35+
36+
exports[`validate options should throw an error on the "unknown" option with "/test/" value 1`] = `
37+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
38+
- options has an unknown property 'unknown'. These properties are valid:
39+
object { flags? }"
40+
`;
41+
42+
exports[`validate options should throw an error on the "unknown" option with "[]" value 1`] = `
43+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
44+
- options has an unknown property 'unknown'. These properties are valid:
45+
object { flags? }"
46+
`;
47+
48+
exports[`validate options should throw an error on the "unknown" option with "{"foo":"bar"}" value 1`] = `
49+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
50+
- options has an unknown property 'unknown'. These properties are valid:
51+
object { flags? }"
52+
`;
53+
54+
exports[`validate options should throw an error on the "unknown" option with "{}" value 1`] = `
55+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
56+
- options has an unknown property 'unknown'. These properties are valid:
57+
object { flags? }"
58+
`;
59+
60+
exports[`validate options should throw an error on the "unknown" option with "1" value 1`] = `
61+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
62+
- options has an unknown property 'unknown'. These properties are valid:
63+
object { flags? }"
64+
`;
65+
66+
exports[`validate options should throw an error on the "unknown" option with "false" value 1`] = `
67+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
68+
- options has an unknown property 'unknown'. These properties are valid:
69+
object { flags? }"
70+
`;
71+
72+
exports[`validate options should throw an error on the "unknown" option with "test" value 1`] = `
73+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
74+
- options has an unknown property 'unknown'. These properties are valid:
75+
object { flags? }"
76+
`;
77+
78+
exports[`validate options should throw an error on the "unknown" option with "true" value 1`] = `
79+
"Invalid options object. Node Loader has been initialized using an options object that does not match the API schema.
80+
- options has an unknown property 'unknown'. These properties are valid:
81+
object { flags? }"
82+
`;

test/loader.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
describe("loader", () => {
1515
it("should work", async () => {
1616
const compiler = getCompiler("simple.js", {
17-
name: "[name].[ext]",
1817
flags: 1,
1918
});
2019
const stats = await compile(compiler);
@@ -30,9 +29,7 @@ describe("loader", () => {
3029
});
3130

3231
it('should throw an error on broken "node" addon', async () => {
33-
const compiler = getCompiler("broken.js", {
34-
name: "[name].[ext]",
35-
});
32+
const compiler = getCompiler("broken.js", {});
3633
const stats = await compile(compiler);
3734

3835
expect(getModuleSource("./broken.node", stats)).toMatchSnapshot("module");

0 commit comments

Comments
 (0)