Skip to content

Commit

Permalink
test: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Feb 17, 2021
1 parent 3888b32 commit 4f646db
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 404 deletions.
92 changes: 92 additions & 0 deletions test/e2e/DevServer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'use strict';

const testBin = require('../helpers/test-bin');
const isWebpack5 = require('../helpers/isWebpack5');

describe('DevServer', () => {
const webpack5Test = isWebpack5 ? it : it.skip;

it('should add devServer entry points to a single entry point', (done) => {
testBin('--config ./test/fixtures/dev-server/default-config.js')
.then((output) => {
expect(output.exitCode).toEqual(0);
expect(output.stderr).toContain('client/default/index.js?');
done();
})
.catch(done);
});

it('should add devServer entry points to a multi entry point object', (done) => {
testBin('--config ./test/fixtures/dev-server/multi-entry.js')
.then((output) => {
expect(output.exitCode).toEqual(0);
expect(output.stderr).toContain('client/default/index.js?');
expect(output.stderr).toContain('foo.js');
expect(output.stderr).toContain('bar.js');
done();
})
.catch(done);
});

webpack5Test('should supports entry as descriptor', (done) => {
testBin('--config ./test/fixtures/entry-as-descriptor/webpack.config --stats detailed')
.then((output) => {
expect(output.exitCode).toEqual(0);
expect(output.stderr).toContain('foo.js');
done();
})
.catch(done);
});

it('should only prepends devServer entry points to "web" target', (done) => {
testBin('--config ./test/fixtures/dev-server/default-config.js --target web')
.then((output) => {
expect(output.exitCode).toEqual(0);
expect(output.stderr).toContain('client/default/index.js?');
expect(output.stderr).toContain('foo.js');
done();
})
.catch(done);
});

it('should not prepend devServer entry points to "node" target', (done) => {
testBin('--config ./test/fixtures/dev-server/default-config.js --target node')
.then((output) => {
expect(output.exitCode).toEqual(0);
expect(output.stderr).not.toContain('client/default/index.js?');
expect(output.stderr).toContain('foo.js');
done();
})
.catch(done);
});

it('should prepends the hot runtime to "node" target as well', (done) => {
testBin('--config ./test/fixtures/dev-server/default-config.js --target node --hot')
.then((output) => {
expect(output.exitCode).toEqual(0);
expect(output.stderr).toContain('webpack/hot/dev-server');
done();
})
.catch(done);
});

it('does not use client.path when default', (done) => {
testBin('--config ./test/fixtures/dev-server/client-default-path-config.js')
.then((output) => {
expect(output.exitCode).toEqual(0);
expect(output.stderr).not.toContain('&path=/ws');
done();
})
.catch(done);
});

it('should use client.path when custom', (done) => {
testBin('--config ./test/fixtures/dev-server/client-custom-path-config.js')
.then((output) => {
expect(output.exitCode).toEqual(0);
expect(output.stderr).toContain('&path=/custom/path');
done();
})
.catch(done);
});
});
1 change: 1 addition & 0 deletions test/fixtures/dev-server/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('I am bar');
16 changes: 16 additions & 0 deletions test/fixtures/dev-server/client-custom-path-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { resolve } = require('path');

module.exports = {
mode: 'development',
stats: 'detailed',
entry: resolve(__dirname, './foo.js'),
devServer: {
client: {
path: '/custom/path',
},
transportMode: {
server: 'sockjs',
client: 'sockjs',
},
}
}
16 changes: 16 additions & 0 deletions test/fixtures/dev-server/client-default-path-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { resolve } = require('path');

module.exports = {
mode: 'development',
stats: 'detailed',
entry: resolve(__dirname, './foo.js'),
devServer: {
client: {
path: '/ws',
},
transportMode: {
server: 'sockjs',
client: 'sockjs',
},
}
}
16 changes: 16 additions & 0 deletions test/fixtures/dev-server/default-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { resolve } = require('path');

module.exports = {
mode: 'development',
stats: 'detailed',
entry: resolve(__dirname, './foo.js'),
devServer: {
client: {
path: '/custom/path',
},
transportMode: {
server: 'sockjs',
client: 'sockjs',
},
}
}
1 change: 1 addition & 0 deletions test/fixtures/dev-server/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('I am foo');
17 changes: 17 additions & 0 deletions test/fixtures/dev-server/multi-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { resolve } = require('path');

module.exports = {
mode: 'development',
stats: 'detailed',
context: __dirname,
entry: {
foo: resolve(__dirname, './foo.js'),
bar: resolve(__dirname, './bar.js'),
},
devServer: {
transportMode: {
server: 'sockjs',
client: 'sockjs',
},
}
}
Loading

0 comments on commit 4f646db

Please sign in to comment.