-
-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
316 additions
and
126 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
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,68 @@ | ||
import path from "path"; | ||
import fs from "fs"; | ||
import util from "util"; | ||
import { rspack, RspackOptions } from "../src"; | ||
import serializer from "jest-serializer-path"; | ||
import assert from "assert"; | ||
import { ensureRspackConfigNotExist } from "./utils"; | ||
|
||
expect.addSnapshotSerializer(serializer); | ||
|
||
const caseDir = path.resolve(__dirname, "./diagnostics"); | ||
const cases = fs.readdirSync(caseDir); | ||
|
||
describe("Diagnostics", function () { | ||
cases.forEach(caseName => { | ||
it(`${caseName} should compiled and match snapshot`, async function () { | ||
const casePath = path.resolve(caseDir, caseName); | ||
ensureRspackConfigNotExist(casePath); | ||
const outputPath = path.resolve(casePath, `./dist`); | ||
const configFile = path.resolve(casePath, "webpack.config.js"); | ||
|
||
let config = {}; | ||
if (fs.existsSync(configFile)) { | ||
config = require(configFile); | ||
} | ||
|
||
let options: RspackOptions = { | ||
target: "node", | ||
context: casePath, | ||
entry: { | ||
main: "./" | ||
}, | ||
mode: "development", | ||
devServer: { | ||
hot: false | ||
}, | ||
infrastructureLogging: { | ||
debug: false | ||
}, | ||
output: { | ||
// @ts-ignore | ||
...config.output, | ||
path: outputPath | ||
} | ||
}; | ||
|
||
if (fs.existsSync(outputPath)) { | ||
fs.rmdirSync(outputPath, { recursive: true }); | ||
} | ||
|
||
const stats = await util.promisify(rspack)(options); | ||
assert(typeof stats !== "undefined"); | ||
assert(stats.hasErrors() || stats.hasWarnings()); | ||
let output = stats | ||
.toString({ timings: false, version: false }) | ||
.replace(/\\/g, "/"); | ||
const errorOutputPath = path.resolve(casePath, `./stats.err`); | ||
const updateSnapshot = | ||
process.argv.includes("-u") || | ||
process.argv.includes("--updateSnapshot"); | ||
if (!fs.existsSync(errorOutputPath) || updateSnapshot) { | ||
fs.writeFileSync(errorOutputPath, output); | ||
} else { | ||
expect(output).toBe(fs.readFileSync(errorOutputPath, "utf-8")); | ||
} | ||
}); | ||
}); | ||
}); |
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 @@ | ||
function add(a: number, b: number): number { | ||
return a + b; | ||
} | ||
|
||
add(1, 2); |
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,21 @@ | ||
PublicPath: (none) | ||
asset main.js 1.21 KiB [emitted] (name: main) | ||
Entrypoint main 1.21 KiB = main.js | ||
./index.js | ||
|
||
ERROR in ./index.js ModuleParseError | ||
|
||
× Module parse failed: | ||
╰─▶ × JavaScript parsing error | ||
╭─[1:1] | ||
1 │ function add(a: number, b: number): number { | ||
· ┬ | ||
· ╰── Expected ',', got ':' | ||
2 │ return a + b; | ||
3 │ } | ||
╰──── | ||
|
||
help: | ||
You may need an appropriate loader to handle this file type. | ||
|
||
Rspack compiled with 1 error (c25b2e90a72c5e9b4a41) |
Oops, something went wrong.