Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Oct 25, 2023
1 parent 4d81bdf commit d8018df
Show file tree
Hide file tree
Showing 33 changed files with 653 additions and 44 deletions.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
45 changes: 45 additions & 0 deletions packages/rspack/tests/configCases/loader/options/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
it("should get options", function () {
expect(require("./a")).toStrictEqual({
arg: true,
arg1: null,
arg3: 1234567890,
arg4: "string",
arg5: [1, 2, 3],
arg6: { foo: "value", bar: { baz: "other-value" } }
});
expect(require("./b")).toStrictEqual({
arg: true,
arg1: null,
arg3: 1234567890,
arg4: "string",
arg5: [1, 2, 3],
arg6: { foo: "value", bar: { baz: "other-value" } }
});
expect(require("./c")).toStrictEqual({
arg: true,
arg1: null,
arg3: 1234567890,
arg4: "string",
arg5: [1, 2, 3],
arg6: { foo: "value", bar: { baz: "other-value" } }
});
expect(require("./d")).toStrictEqual({
arg4: "text"
});
expect(require("./e")).toStrictEqual({});
expect(require("./f")).toStrictEqual({
delicious: "",
name: "cheesecake",
slices: "8",
warm: "false"
});
expect(require("./g")).toStrictEqual({
"=": "="
});
expect(require("./h")).toStrictEqual({
foo: "bar"
});
expect(require("./i")).toStrictEqual({
foo: "bar"
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: Compilation\/modules.+loaders[/\\]options[/\\]error1\.js$/
];
12 changes: 12 additions & 0 deletions packages/rspack/tests/configCases/loader/options/loader-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const schema = require("./loader-1.options.json");

/** @type {import("@rspack/core").LoaderDefinition} */
module.exports = function () {
const options = this.getOptions(schema);

const json = JSON.stringify(options)
.replace(/\u2028/g, "\\u2028")
.replace(/\u2029/g, "\\u2029");

return `module.exports = ${json}`;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"additionalProperties": false,
"properties": {
"arg": {
"type": "boolean"
},
"arg1": {
"type": "null"
},
"arg2": {},
"arg3": {
"type": "number"
},
"arg4": {
"type": "string"
},
"arg5": {
"type": "array",
"items": {
"type": "number"
}
},
"arg6": {
"type": "object",
"properties": {
"foo": {
"type": "string"
},
"bar": {
"type": "object",
"properties": {
"baz": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
},
"type": "object"
}
12 changes: 12 additions & 0 deletions packages/rspack/tests/configCases/loader/options/loader-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const schema = require("./loader-2.options.json");

/** @type {import("@rspack/core").LoaderDefinition} */
module.exports = function () {
const options = this.getOptions(schema);

const json = JSON.stringify(options)
.replace(/\u2028/g, "\\u2028")
.replace(/\u2029/g, "\\u2029");

return `module.exports = ${json}`;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"title": "Custom Loader Name configuration",
"additionalProperties": false,
"properties": {
"arg": {
"enum": [true]
}
},
"type": "object"
}
10 changes: 10 additions & 0 deletions packages/rspack/tests/configCases/loader/options/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import("@rspack/core").LoaderDefinition} */
module.exports = function () {
const options = this.getOptions();

const json = JSON.stringify(options)
.replace(/\u2028/g, "\\u2028")
.replace(/\u2029/g, "\\u2029");

return `module.exports = ${json}`;
};
93 changes: 93 additions & 0 deletions packages/rspack/tests/configCases/loader/options/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
mode: "none",
module: {
rules: [
{
test: /a\.js$/,
loader: "./loader",
options: {
arg: true,
arg1: null,
arg2: undefined,
arg3: 1234567890,
arg4: "string",
arg5: [1, 2, 3],
arg6: { foo: "value", bar: { baz: "other-value" } }
}
},
{
test: /b\.js$/,
loader: "./loader-1",
options: {
arg: true,
arg1: null,
arg2: undefined,
arg3: 1234567890,
arg4: "string",
arg5: [1, 2, 3],
arg6: { foo: "value", bar: { baz: "other-value" } }
}
},
{
test: /c\.js$/,
loader: "./loader-1",
options: JSON.stringify({
arg: true,
arg1: null,
arg2: undefined,
arg3: 1234567890,
arg4: "string",
arg5: [1, 2, 3],
arg6: { foo: "value", bar: { baz: "other-value" } }
})
},
{
test: /d\.js$/,
loader: "./loader-1",
options: "arg4=text"
},
{
test: /d\.js$/,
loader: "./loader",
options: ""
},
{
test: /f\.js$/,
loader: "./loader",
options: "name=cheesecake&slices=8&delicious&warm=false"
},
{
test: /g\.js$/,
loader: "./loader",
options: "%3d=%3D"
},
{
test: /h\.js$/,
loader: "./loader",
options: "foo=bar"
},
{
test: /i\.js$/,
loader: "./loader",
options: `${JSON.stringify({
foo: "bar"
})}`
},
{
test: /error1\.js$/,
loader: "./loader-1",
options: {
arg6: { foo: "value", bar: { baz: 42 } }
}
},
{
test: /error2\.js$/,
loader: "./loader-2",
options: {
arg: false
}
}
]
}
};
Loading

0 comments on commit d8018df

Please sign in to comment.