Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions test/stats/stats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions test/zero-config/entry-absent/zero-config.test.js
Original file line number Diff line number Diff line change
@@ -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("Error: Can't resolve './src'");
expect(stderr).toBeFalsy();
});
});
1 change: 1 addition & 0 deletions test/zero-config/entry-present/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Shoyo")
16 changes: 16 additions & 0 deletions test/zero-config/entry-present/zero-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fs = require('fs');
const path = require('path');
const { run } = require('../../utils/test-utils');

describe('Zero Config tests', () => {
it('runs when no config is supplied but entry is present', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also test for existence of bundle output file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can def do that, thinking if this would be the right scope for it as output file check is something which is config/flag agnostic. wdyt? Since we're not checking for it anywhere else, should be also checked for it in all other tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe we can just check the test util since it's used everywhere, will add tests for the run fn that we use in all tests separately. Would make more sense to check file existence there.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particular case we should test it either way imo. Because the test is for checking whether without config we are bundling or not.

Tests for run as well in a different PR would be great :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe we can just check the test util since it's used everywhere, will add tests for the run fn that we use in all tests separately. Would make more sense to check file existence there.

We're consuming the run fn for couple of test cases where bundle output is not generated, say the migrate command. It should be taken into account while writing the respective tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fair, added. 👍

const { stdout, stderr } = run(__dirname, [], false);
// Should be able to find the entry file
expect(stdout).toContain('./src/index.js');
// Should output at the default output dir and filename
expect(stdout).toContain('Entrypoint main = main.js');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have it, only entry present and config absent. @evilebottnawi

// check that the output file exists
expect(fs.existsSync(path.join(__dirname, '/dist/main.js'))).toBeTruthy();
expect(stderr).toBeFalsy();
});
});
1 change: 1 addition & 0 deletions test/zero-config/with-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Naruto")
6 changes: 6 additions & 0 deletions test/zero-config/with-config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
mode: 'development',
output: {
filename: 'test-output.js',
},
};
16 changes: 16 additions & 0 deletions test/zero-config/with-config/zero-config-entry.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fs = require('fs');
const path = require('path');
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);
// 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');
// check that the output file exists
expect(fs.existsSync(path.join(__dirname, '/dist/test-output.js'))).toBeTruthy();
expect(stderr).toBeFalsy();
});
});