Skip to content

Commit

Permalink
tests: publicPath
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 28, 2020
1 parent bb16d44 commit cf4efb7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/serve/basic/dev-server-output-public-path.config.js
@@ -0,0 +1,13 @@
const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin');

module.exports = {
mode: 'development',
devtool: false,
output: {
publicPath: '/my-public-path/',
},
devServer: {
publicPath: '/dev-server-my-public-path/',
},
plugins: [new WebpackCLITestPlugin(['mode', 'output'], false, 'hooks.compilation.taps')],
};
10 changes: 10 additions & 0 deletions test/serve/basic/output-public-path.config.js
@@ -0,0 +1,10 @@
const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin');

module.exports = {
mode: 'development',
devtool: false,
output: {
publicPath: '/my-public-path/',
},
plugins: [new WebpackCLITestPlugin(['mode', 'output'], false, 'hooks.compilation.taps')],
};
28 changes: 28 additions & 0 deletions test/serve/basic/serve-basic.test.js
Expand Up @@ -141,6 +141,34 @@ describe('basic serve usage', () => {
expect(stdout.match(/HotModuleReplacementPlugin/g)).toHaveLength(1);
});

// TODO uncomment for webpack-dev-server@4
it.skip('should work with the "--output-public-path" option', async () => {
const { stderr, stdout } = await runServe(['serve', '--output-public-path', '/my-public-path/'], __dirname);

expect(stderr).toBeFalsy();
expect(stdout).toContain('main.js');
expect(stdout).toContain('/my-public-path/');
expect(stdout.match(/HotModuleReplacementPlugin/g)).toBeNull();
});

it('should respect the "publicPath" option from configuration', async () => {
const { stderr, stdout } = await runServe(['serve', '--config', 'output-public-path.config.js'], __dirname);

expect(stderr).toBeFalsy();
expect(stdout).toContain('main.js');
expect(stdout).toContain('/my-public-path/');
expect(stdout.match(/HotModuleReplacementPlugin/g)).toBeNull();
});

it('should respect the "publicPath" option from configuration (from the "devServer" options)', async () => {
const { stderr, stdout } = await runServe(['serve', '--config', 'dev-server-output-public-path.config.js'], __dirname);

expect(stderr).toBeFalsy();
expect(stdout).toContain('main.js');
expect(stdout).toContain('/dev-server-my-public-path/');
expect(stdout.match(/HotModuleReplacementPlugin/g)).toBeNull();
});

it('should log and error on unknown flag', async () => {
const { exitCode, stdout, stderr } = await runServe(['--port', port, '--unknown-flag'], testPath);

Expand Down

0 comments on commit cf4efb7

Please sign in to comment.