From ffc8a131cfe55ce642cadb10109f7933daf34403 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Sat, 4 Apr 2020 13:47:45 +0530 Subject: [PATCH 1/6] tests: add tests for zero config --- test/stats/stats.test.js | 2 -- test/zero-config/entry-absent/zero-config.test.js | 10 ++++++++++ test/zero-config/entry-present/src/index.js | 1 + .../zero-config/entry-present/zero-config.test.js | 13 +++++++++++++ test/zero-config/with-config/index.js | 1 + test/zero-config/with-config/webpack.config.js | 6 ++++++ .../with-config/zero-config-entry.test.js | 15 +++++++++++++++ 7 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 test/zero-config/entry-absent/zero-config.test.js create mode 100644 test/zero-config/entry-present/src/index.js create mode 100644 test/zero-config/entry-present/zero-config.test.js create mode 100644 test/zero-config/with-config/index.js create mode 100644 test/zero-config/with-config/webpack.config.js create mode 100644 test/zero-config/with-config/zero-config-entry.test.js diff --git a/test/stats/stats.test.js b/test/stats/stats.test.js index b6faa4fcabe..7eca9cf0e2e 100644 --- a/test/stats/stats.test.js +++ b/test/stats/stats.test.js @@ -3,8 +3,6 @@ const { run } = require('../utils/test-utils'); describe('stats flag', () => { - // { - // StatsGroup.validOptions().map(option => { it('should accept stats "none"', () => { const { stderr, stdout } = run(__dirname, ['--stats', 'none']); expect(stderr).toBeFalsy(); diff --git a/test/zero-config/entry-absent/zero-config.test.js b/test/zero-config/entry-absent/zero-config.test.js new file mode 100644 index 00000000000..bb4d47a1745 --- /dev/null +++ b/test/zero-config/entry-absent/zero-config.test.js @@ -0,0 +1,10 @@ +const { run } = require('../../utils/test-utils'); + +describe('Zero Config tests', () => { + it('runs when config and entry are both absent', () => { + const { stdout, stderr } = run(__dirname, [], false); + // Entry file is absent, should log the Error from the compiler + expect(stdout).toContain("Module not found: Error: Can't resolve './src'"); + expect(stderr).toBeFalsy(); + }); +}); diff --git a/test/zero-config/entry-present/src/index.js b/test/zero-config/entry-present/src/index.js new file mode 100644 index 00000000000..655f0d1539f --- /dev/null +++ b/test/zero-config/entry-present/src/index.js @@ -0,0 +1 @@ +console.log("Shoyo") diff --git a/test/zero-config/entry-present/zero-config.test.js b/test/zero-config/entry-present/zero-config.test.js new file mode 100644 index 00000000000..752c2e25cf0 --- /dev/null +++ b/test/zero-config/entry-present/zero-config.test.js @@ -0,0 +1,13 @@ +const { run } = require('../../utils/test-utils'); + +describe('Zero Config tests', () => { + it('runs when no config is supplied but entry is present', () => { + const { stdout, stderr } = run(__dirname, [], false); + // Should be able to find the entry file + expect(stdout).not.toContain("Module not found: Error: Can't resolve './src'"); + expect(stdout).toContain('./src/index.js 21 bytes [built]'); + // Should output at the default output dir and filename + expect(stdout).toContain('Entrypoint main = main.js'); + expect(stderr).toBeFalsy(); + }); +}); diff --git a/test/zero-config/with-config/index.js b/test/zero-config/with-config/index.js new file mode 100644 index 00000000000..fcb6413e9b3 --- /dev/null +++ b/test/zero-config/with-config/index.js @@ -0,0 +1 @@ +console.log("Naruto") diff --git a/test/zero-config/with-config/webpack.config.js b/test/zero-config/with-config/webpack.config.js new file mode 100644 index 00000000000..fed2ef3bf1e --- /dev/null +++ b/test/zero-config/with-config/webpack.config.js @@ -0,0 +1,6 @@ +module.exports = { + mode: 'development', + output: { + filename: 'test-output', + }, +}; diff --git a/test/zero-config/with-config/zero-config-entry.test.js b/test/zero-config/with-config/zero-config-entry.test.js new file mode 100644 index 00000000000..22426baae92 --- /dev/null +++ b/test/zero-config/with-config/zero-config-entry.test.js @@ -0,0 +1,15 @@ +const { run } = require('../../utils/test-utils'); + +describe('Zero Config', () => { + it('runs when config is present but not supplied via flag', () => { + const { stdout, stderr } = run(__dirname, [], false); + console.log({ stdout, stderr }); + // Should find the entry file, thus not throw the below warning + expect(stdout).not.toContain("Module not found: Error: Can't resolve './src'"); + // default entry should be used + expect(stdout).toContain('./index.js 22 bytes [built]'); + // should pick up the output path from config + expect(stdout).toContain('Entrypoint main = test-output\n./index.js'); + expect(stderr).toBeFalsy(); + }); +}); From 5baf8a689a7b534ae69a4ecc05d7a58c25089b53 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Sat, 4 Apr 2020 14:00:05 +0530 Subject: [PATCH 2/6] tests: add tests for zero config --- test/zero-config/entry-absent/zero-config.test.js | 2 +- test/zero-config/entry-present/zero-config.test.js | 2 +- test/zero-config/with-config/zero-config-entry.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/zero-config/entry-absent/zero-config.test.js b/test/zero-config/entry-absent/zero-config.test.js index bb4d47a1745..9acc630d895 100644 --- a/test/zero-config/entry-absent/zero-config.test.js +++ b/test/zero-config/entry-absent/zero-config.test.js @@ -4,7 +4,7 @@ describe('Zero Config tests', () => { it('runs when config and entry are both absent', () => { const { stdout, stderr } = run(__dirname, [], false); // Entry file is absent, should log the Error from the compiler - expect(stdout).toContain("Module not found: Error: Can't resolve './src'"); + expect(stdout).toContain("Error: Can't resolve './src'"); expect(stderr).toBeFalsy(); }); }); diff --git a/test/zero-config/entry-present/zero-config.test.js b/test/zero-config/entry-present/zero-config.test.js index 752c2e25cf0..f3c24607245 100644 --- a/test/zero-config/entry-present/zero-config.test.js +++ b/test/zero-config/entry-present/zero-config.test.js @@ -5,7 +5,7 @@ describe('Zero Config tests', () => { const { stdout, stderr } = run(__dirname, [], false); // Should be able to find the entry file expect(stdout).not.toContain("Module not found: Error: Can't resolve './src'"); - expect(stdout).toContain('./src/index.js 21 bytes [built]'); + expect(stdout).toContain('./src/index.js'); // Should output at the default output dir and filename expect(stdout).toContain('Entrypoint main = main.js'); expect(stderr).toBeFalsy(); diff --git a/test/zero-config/with-config/zero-config-entry.test.js b/test/zero-config/with-config/zero-config-entry.test.js index 22426baae92..d2e7116ff87 100644 --- a/test/zero-config/with-config/zero-config-entry.test.js +++ b/test/zero-config/with-config/zero-config-entry.test.js @@ -7,7 +7,7 @@ describe('Zero Config', () => { // Should find the entry file, thus not throw the below warning expect(stdout).not.toContain("Module not found: Error: Can't resolve './src'"); // default entry should be used - expect(stdout).toContain('./index.js 22 bytes [built]'); + expect(stdout).toContain('./index.js'); // should pick up the output path from config expect(stdout).toContain('Entrypoint main = test-output\n./index.js'); expect(stderr).toBeFalsy(); From 05c8eff70c5e0bcf4418229590ebe6739c28e957 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Sat, 4 Apr 2020 14:07:19 +0530 Subject: [PATCH 3/6] tests: add tests for zero config --- test/zero-config/with-config/zero-config-entry.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/zero-config/with-config/zero-config-entry.test.js b/test/zero-config/with-config/zero-config-entry.test.js index d2e7116ff87..b58a5067b7e 100644 --- a/test/zero-config/with-config/zero-config-entry.test.js +++ b/test/zero-config/with-config/zero-config-entry.test.js @@ -9,7 +9,7 @@ describe('Zero Config', () => { // default entry should be used expect(stdout).toContain('./index.js'); // should pick up the output path from config - expect(stdout).toContain('Entrypoint main = test-output\n./index.js'); + expect(stdout).toContain('Entrypoint main = test-output'); expect(stderr).toBeFalsy(); }); }); From ad1e9dc0501765af939ffdc5df738f5a5a0a3d63 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Sat, 4 Apr 2020 18:00:30 +0530 Subject: [PATCH 4/6] tests: add tests for zero config --- test/zero-config/with-config/zero-config-entry.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/zero-config/with-config/zero-config-entry.test.js b/test/zero-config/with-config/zero-config-entry.test.js index b58a5067b7e..e524110f21f 100644 --- a/test/zero-config/with-config/zero-config-entry.test.js +++ b/test/zero-config/with-config/zero-config-entry.test.js @@ -3,7 +3,6 @@ const { run } = require('../../utils/test-utils'); describe('Zero Config', () => { it('runs when config is present but not supplied via flag', () => { const { stdout, stderr } = run(__dirname, [], false); - console.log({ stdout, stderr }); // Should find the entry file, thus not throw the below warning expect(stdout).not.toContain("Module not found: Error: Can't resolve './src'"); // default entry should be used From 661f9a66be79d9fedf01f043f73482eb4dc74a9e Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Mon, 6 Apr 2020 16:23:38 +0530 Subject: [PATCH 5/6] tests: add tests for zero config --- test/zero-config/entry-present/zero-config.test.js | 1 - test/zero-config/with-config/zero-config-entry.test.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/test/zero-config/entry-present/zero-config.test.js b/test/zero-config/entry-present/zero-config.test.js index f3c24607245..aa4a003492c 100644 --- a/test/zero-config/entry-present/zero-config.test.js +++ b/test/zero-config/entry-present/zero-config.test.js @@ -4,7 +4,6 @@ describe('Zero Config tests', () => { it('runs when no config is supplied but entry is present', () => { const { stdout, stderr } = run(__dirname, [], false); // Should be able to find the entry file - expect(stdout).not.toContain("Module not found: Error: Can't resolve './src'"); expect(stdout).toContain('./src/index.js'); // Should output at the default output dir and filename expect(stdout).toContain('Entrypoint main = main.js'); diff --git a/test/zero-config/with-config/zero-config-entry.test.js b/test/zero-config/with-config/zero-config-entry.test.js index e524110f21f..95f500c3004 100644 --- a/test/zero-config/with-config/zero-config-entry.test.js +++ b/test/zero-config/with-config/zero-config-entry.test.js @@ -3,8 +3,6 @@ const { run } = require('../../utils/test-utils'); describe('Zero Config', () => { it('runs when config is present but not supplied via flag', () => { const { stdout, stderr } = run(__dirname, [], false); - // Should find the entry file, thus not throw the below warning - expect(stdout).not.toContain("Module not found: Error: Can't resolve './src'"); // default entry should be used expect(stdout).toContain('./index.js'); // should pick up the output path from config From 7af3ff4ed5cc2184e46d6a5863632a84dd59ab41 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Mon, 6 Apr 2020 23:50:25 +0530 Subject: [PATCH 6/6] tests: add checks for existence of bundled file --- test/zero-config/entry-present/zero-config.test.js | 4 ++++ test/zero-config/with-config/webpack.config.js | 2 +- test/zero-config/with-config/zero-config-entry.test.js | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/zero-config/entry-present/zero-config.test.js b/test/zero-config/entry-present/zero-config.test.js index aa4a003492c..556db6c6b49 100644 --- a/test/zero-config/entry-present/zero-config.test.js +++ b/test/zero-config/entry-present/zero-config.test.js @@ -1,3 +1,5 @@ +const fs = require('fs'); +const path = require('path'); const { run } = require('../../utils/test-utils'); describe('Zero Config tests', () => { @@ -7,6 +9,8 @@ describe('Zero Config tests', () => { expect(stdout).toContain('./src/index.js'); // Should output at the default output dir and filename expect(stdout).toContain('Entrypoint main = main.js'); + // check that the output file exists + expect(fs.existsSync(path.join(__dirname, '/dist/main.js'))).toBeTruthy(); expect(stderr).toBeFalsy(); }); }); diff --git a/test/zero-config/with-config/webpack.config.js b/test/zero-config/with-config/webpack.config.js index fed2ef3bf1e..6593a7a44a3 100644 --- a/test/zero-config/with-config/webpack.config.js +++ b/test/zero-config/with-config/webpack.config.js @@ -1,6 +1,6 @@ module.exports = { mode: 'development', output: { - filename: 'test-output', + filename: 'test-output.js', }, }; diff --git a/test/zero-config/with-config/zero-config-entry.test.js b/test/zero-config/with-config/zero-config-entry.test.js index 95f500c3004..53825d5ad8f 100644 --- a/test/zero-config/with-config/zero-config-entry.test.js +++ b/test/zero-config/with-config/zero-config-entry.test.js @@ -1,3 +1,5 @@ +const fs = require('fs'); +const path = require('path'); const { run } = require('../../utils/test-utils'); describe('Zero Config', () => { @@ -7,6 +9,8 @@ describe('Zero Config', () => { expect(stdout).toContain('./index.js'); // should pick up the output path from config expect(stdout).toContain('Entrypoint main = test-output'); + // check that the output file exists + expect(fs.existsSync(path.join(__dirname, '/dist/test-output.js'))).toBeTruthy(); expect(stderr).toBeFalsy(); }); });