Skip to content

Commit

Permalink
refactor: config tests (#2939)
Browse files Browse the repository at this point in the history
* fix: absent config test

* chore: basic config description

* chore: update default js config test

* chore: update dot webpack config test

* chore: update dot webpack webpackfile test

* chore: fix description of cjs config

* chore: update mjs config

* chore: default config with mode

* chore: fix empty test

* chore: update empty array

* chore: update empty function descriptions

* chore: update empty promise

* chore: update config array error

* chore: update no config

* chore: update invalid path file

* chore: update config error test

* chore: fix funtional config test

* chore: invalid export

* chore: update multiple config test

* chore: update config test

* chore: update no code test

* chore: update no config array test

* chore: update no config object test
  • Loading branch information
rishabh3112 committed Sep 22, 2021
1 parent da135dd commit c8db7d5
Show file tree
Hide file tree
Showing 25 changed files with 38 additions and 57 deletions.
4 changes: 2 additions & 2 deletions test/build/config/absent/config-absent.test.js
Expand Up @@ -3,8 +3,8 @@
const path = require("path");
const { run } = require("../../../utils/test-utils");

describe("Config:", () => {
it("supplied config file is absent", async () => {
describe("config flag with non existent file", () => {
it("should throw error with non-existent configuration file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
path.resolve(__dirname, "webpack.config.js"),
Expand Down
9 changes: 0 additions & 9 deletions test/build/config/absent/webpack.config-absent.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/build/config/basic/basic-config.test.js
Expand Up @@ -4,7 +4,7 @@ const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("basic config file", () => {
it("is able to understand and parse a very basic configuration file", async () => {
it("should build and not throw error with a basic configuration file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
Expand Down
Expand Up @@ -2,8 +2,8 @@ const fs = require("fs");
const path = require("path");
const { run, isWebpack5 } = require("../../../../utils/test-utils");

describe("Zero Config", () => {
it("runs when config is present but not supplied via flag", async () => {
describe("default config", () => {
it("should build and not throw error when config is present but not supplied via flag", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, []);

expect(exitCode).toEqual(0);
Expand Down
Expand Up @@ -2,8 +2,8 @@ const fs = require("fs");
const path = require("path");
const { run, isWebpack5 } = require("../../../../utils/test-utils");

describe("Default Config:", () => {
it("Should be able to pick cjs config by default", async () => {
describe("default config with cjs extention", () => {
it("should build and not throw error with cjs config by default", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, []);

expect(exitCode).toEqual(0);
Expand Down
Expand Up @@ -3,8 +3,8 @@ const { existsSync } = require("fs");
const { resolve } = require("path");
const { run } = require("../../../../utils/test-utils");

describe("multiple dev config files with webpack.config.js", () => {
it("Uses webpack.config.development.js", async () => {
describe(".webpack webpackfile", () => {
it("should build and not throw with .webpack webpackfile", async () => {
const { stdout, stderr, exitCode } = await run(__dirname, []);
expect(exitCode).toEqual(0);
expect(stderr).toBeFalsy();
Expand Down
Expand Up @@ -3,8 +3,8 @@ const { existsSync } = require("fs");
const { resolve } = require("path");
const { run } = require("../../../../utils/test-utils");

describe("multiple config files", () => {
it("Uses dev config when both dev and none are present", async () => {
describe(".webpack configuration file", () => {
it("should build and not throw error when config is present in .webpack", async () => {
const { stdout, stderr, exitCode } = await run(__dirname, []);
expect(exitCode).toEqual(0);
expect(stderr).toBeFalsy();
Expand Down
Expand Up @@ -2,8 +2,8 @@ const fs = require("fs");
const path = require("path");
const { run, isWebpack5 } = require("../../../../utils/test-utils");

describe("Default Config:", () => {
it("Should be able to pick mjs config by default", async () => {
describe("default config with mjs extention", () => {
it("should build and not throw error with mjs config by default", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [], {
env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true },
});
Expand Down
Expand Up @@ -3,8 +3,8 @@ const { existsSync } = require("fs");
const { resolve } = require("path");
const { run } = require("../../../../utils/test-utils");

describe("multiple config files", () => {
it("Uses dev config when development mode is supplied", async () => {
describe("default config with mode from cli", () => {
it("should build and not throw error with development mode supplied", async () => {
const { stdout, stderr, exitCode } = await run(__dirname, ["--mode", "development"]);
expect(exitCode).toEqual(0);
expect(stderr).toBeFalsy();
Expand Down
4 changes: 2 additions & 2 deletions test/build/config/empty-array/empty-array.test.js
Expand Up @@ -2,8 +2,8 @@
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("config flag with empty config file", () => {
it("should throw error with no configuration or index file", async () => {
describe("config flag with config file returning empty array", () => {
it("should build and not throw error with no configuration or index file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
Expand Down
4 changes: 2 additions & 2 deletions test/build/config/empty-function/empty-function.test.js
Expand Up @@ -2,8 +2,8 @@
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("config flag with empty config file", () => {
it("should throw error with no configuration or index file", async () => {
describe("config file with function returning empty object", () => {
it("should build and not throw error with no configuration or index file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
Expand Down
4 changes: 2 additions & 2 deletions test/build/config/empty-promise/empty-promise.test.js
Expand Up @@ -2,8 +2,8 @@
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("config flag with empty config file", () => {
it("should throw error with no configuration or index file", async () => {
describe("config file with promise resolving empty object", () => {
it("should build and not throw error with no configuration or index file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
Expand Down
2 changes: 1 addition & 1 deletion test/build/config/empty/empty.test.js
Expand Up @@ -3,7 +3,7 @@ const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("config flag with empty config file", () => {
it("should throw error with no configuration or index file", async () => {
it("should build and not throw error with no configuration or index file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
Expand Down
2 changes: 1 addition & 1 deletion test/build/config/error-array/config-array-error.test.js
@@ -1,7 +1,7 @@
"use strict";
const { run } = require("../../../utils/test-utils");

describe("array config error", () => {
describe("config with invalid array syntax", () => {
it("should throw syntax error and exit with non-zero exit code when even 1 object has syntax error", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"]);
expect(exitCode).toBe(2);
Expand Down
2 changes: 1 addition & 1 deletion test/build/config/error-commonjs/config-error.test.js
Expand Up @@ -2,7 +2,7 @@
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("config error", () => {
describe("config with errors", () => {
it("should throw error with invalid configuration", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
Expand Down
4 changes: 2 additions & 2 deletions test/build/config/function/functional-config.test.js
Expand Up @@ -5,7 +5,7 @@ const { existsSync } = require("fs");
const { run } = require("../../../utils/test-utils");

describe("functional config", () => {
it("should work as expected in case of single config", async () => {
it("should build and not throw error with single configuration", async () => {
const { stderr, stdout, exitCode } = await run(__dirname, [
"--config",
resolve(__dirname, "single-webpack.config.js"),
Expand All @@ -17,7 +17,7 @@ describe("functional config", () => {
expect(existsSync(resolve(__dirname, "./dist/dist-single.js"))).toBeTruthy();
});

it("should work as expected in case of multiple config", async () => {
it("should build and not throw errors with multiple configurations", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"--config",
resolve(__dirname, "multi-webpack.config.js"),
Expand Down
4 changes: 2 additions & 2 deletions test/build/config/invalid-export/invalid-export.test.js
Expand Up @@ -2,8 +2,8 @@
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("invalid export", () => {
it("should throw error with no configuration or index file", async () => {
describe("config with invalid export", () => {
it("should throw error with configuration exporting invalid configuration", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
Expand Down
1 change: 0 additions & 1 deletion test/build/config/invalid-path/a.js

This file was deleted.

4 changes: 2 additions & 2 deletions test/build/config/invalid-path/invalid-path.test.js
Expand Up @@ -2,8 +2,8 @@
const path = require("path");
const { run } = require("../../../utils/test-utils");

describe("basic config file", () => {
it("is able to understand and parse a very basic configuration file", async () => {
describe("config with invalid path supplied by CLI", () => {
it("should throw error when invalid configuration path is passed to cli", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
path.resolve(__dirname, "invalid-webpack.config.js"),
Expand Down
9 changes: 0 additions & 9 deletions test/build/config/invalid-path/webpack.config.js

This file was deleted.

Expand Up @@ -3,8 +3,8 @@
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("basic config file", () => {
it("is able to understand and parse a very basic configuration file", async () => {
describe("config with single config in array", () => {
it("should build and not throw error with configuration file exporting single configuration in array", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
Expand Down
4 changes: 2 additions & 2 deletions test/build/config/multiple/multiple-config.test.js
Expand Up @@ -2,8 +2,8 @@

const { run } = require("../../../utils/test-utils");

describe("Multiple config flag: ", () => {
it("spawns multiple compilers for multiple configs", async () => {
describe("multiple configuration files", () => {
it("should not throw error and spawn compilers for each configuration file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"--config",
"webpack1.config.js",
Expand Down
2 changes: 1 addition & 1 deletion test/build/config/no-code/no-code.test.js
Expand Up @@ -3,7 +3,7 @@ const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("config flag with no code", () => {
it("should not throw error with no configuration or index file", async () => {
it("should build and not throw error with no configuration or index file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
Expand Down
4 changes: 2 additions & 2 deletions test/build/config/no-config-array/no-config-array.test.js
Expand Up @@ -3,8 +3,8 @@
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("no configs in array", () => {
it("is able to understand and parse a very basic configuration file", async () => {
describe("config with empty array", () => {
it("should build and not throw error with empty configuration", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
Expand Down
Expand Up @@ -4,7 +4,7 @@ const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("empty config", () => {
it("should work", async () => {
it("should build and not throw error with empty object as configuration", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
resolve(__dirname, "webpack.config.js"),
Expand Down

0 comments on commit c8db7d5

Please sign in to comment.