Skip to content

Commit

Permalink
test: add test for typescript config file
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme committed Mar 13, 2023
1 parent 374c42e commit de32937
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-cameras-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rspack/cli": minor
---

Support TypeScript as configuration file.
1 change: 1 addition & 0 deletions packages/rspack-cli/tests/build/typescript/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Main typescript file");
12 changes: 12 additions & 0 deletions packages/rspack-cli/tests/build/typescript/rspack.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as path from "path";

const config = {
mode: "production",
entry: "./main.ts",
output: {
path: path.resolve(__dirname, "dist"),
filename: "foo.bundle.js",
},
};

export = config;
5 changes: 5 additions & 0 deletions packages/rspack-cli/tests/build/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
26 changes: 26 additions & 0 deletions packages/rspack-cli/tests/build/typescript/typescript.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { run } from "../../utils/test-utils";
import { existsSync } from "fs";
import { resolve } from "path";

describe("webpack cli", () => {
it("should support default config in typescript", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, []);

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});

it("should support specifying config in typescript", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
"./rspack.config.ts"
]);

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});
});

0 comments on commit de32937

Please sign in to comment.