Skip to content

Commit

Permalink
refactor: standalone test
Browse files Browse the repository at this point in the history
  • Loading branch information
shuta13 committed Jul 17, 2022
1 parent d4673f1 commit 46eb622
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { run } = require("../../../utils/test-utils");
const { existsSync, unlinkSync } = require("fs");
const { resolve } = require("path");

// eslint-disable-next-line node/no-unpublished-require
const execa = require("execa");
const { sync: spawnSync } = execa;

describe("webpack cli", () => {
it('should work with the "disable-interpret" option from flags', async () => {
const configFileName = "webpack.config";
const configFilePath = resolve(__dirname, `${configFileName}.ts`);
const buildScripts = spawnSync("yarn", ["tsc", configFilePath]);
expect(buildScripts.stdout).toBeTruthy();

const { exitCode, stderr, stdout } = await run(__dirname, ["--disable-interpret"]);
unlinkSync(resolve(__dirname, `${configFileName}.js`));

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});
});
1 change: 1 addition & 0 deletions test/build/config-format/disable-interpret/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Main typescript file");
5 changes: 5 additions & 0 deletions test/build/config-format/disable-interpret/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
14 changes: 14 additions & 0 deletions test/build/config-format/disable-interpret/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable node/no-unsupported-features/es-syntax */
/** eslint-disable **/
import * as path from "path";

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

export = config;
21 changes: 1 addition & 20 deletions test/build/config-format/typescript/typescript.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
const { run } = require("../../../utils/test-utils");
const { existsSync, unlinkSync } = require("fs");
const { existsSync } = require("fs");
const { resolve } = require("path");

// eslint-disable-next-line node/no-unpublished-require
const execa = require("execa");
const { sync: spawnSync } = execa;

describe("webpack cli", () => {
it("should support typescript file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.ts"]);
Expand All @@ -15,19 +11,4 @@ describe("webpack cli", () => {
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});

it('should work with the "disable-interpret" option from flags', async () => {
const configFileName = "webpack.config";
const configFilePath = resolve(__dirname, `${configFileName}.ts`);
const buildScripts = spawnSync("yarn", ["tsc", configFilePath]);
expect(buildScripts.stdout).toBeTruthy();

const { exitCode, stderr, stdout } = await run(__dirname, ["--disable-interpret"]);
unlinkSync(resolve(__dirname, `${configFileName}.js`));

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

0 comments on commit 46eb622

Please sign in to comment.