-
-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
147 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { replaceAt, generatePluginName } from '../../lib/utils/plugins'; | ||
|
||
describe('generate plugin name', () => { | ||
it('should return webpack Standard Plugin Name for Name : extract-text-webpack-plugin', () => { | ||
const pluginName = generatePluginName('extract-text-webpack-plugin'); | ||
expect(pluginName).toEqual('ExtractTextWebpackPlugin'); | ||
}); | ||
|
||
it('should return webpack Standard Plugin Name for Name : webpack.DefinePlugin', () => { | ||
const pluginName = generatePluginName('webpack.DefinePlugin'); | ||
expect(pluginName).toEqual('webpack.DefinePlugin'); | ||
}); | ||
|
||
it('should return webpack Standard Plugin Name for Name : my-plugin-name-1', () => { | ||
const pluginName = generatePluginName('my-plugin-name-1'); | ||
expect(pluginName).toEqual('MyPluginName1'); | ||
}); | ||
|
||
it('replaceAt capitalizes first letter', () => { | ||
expect(replaceAt('mystring', 0, 'M')).toEqual('Mystring'); | ||
}); | ||
|
||
it('replaceAt replaces within string', () => { | ||
expect(replaceAt('mystring', 2, '-inserted-')).toEqual('my-inserted-tring'); | ||
}); | ||
|
||
it('replaceAt replaces at end of string', () => { | ||
expect(replaceAt('mystring', 7, '-inserted-')).toEqual('mystrin-inserted-'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const { run } = require('../../utils/test-utils'); | ||
const { stat, readFile } = require('fs'); | ||
const { resolve } = require('path'); | ||
|
||
describe('entry flag', () => { | ||
it('should load ./src/a.js as entry', (done) => { | ||
const { stderr, stdout } = run(__dirname, ['--entry', './src/a.js']); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toBeTruthy(); | ||
|
||
stat(resolve(__dirname, './bin/main.js'), (err, stats) => { | ||
expect(err).toBe(null); | ||
expect(stats.isFile()).toBe(true); | ||
done(); | ||
}); | ||
readFile(resolve(__dirname, './bin/main.js'), 'utf-8', (err, data) => { | ||
expect(err).toBe(null); | ||
expect(data).toContain('Hello from a.js'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should throw error for invalid entry file', () => { | ||
const { stderr, stdout } = run(__dirname, ['--entry', './src/test.js']); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain('not found'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('Hello from a.js'); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('Kageyama Tobio'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const getPort = require('get-port'); | ||
const { runServe } = require('../../utils/test-utils'); | ||
|
||
const testPath = path.resolve(__dirname); | ||
|
||
describe('serve with devServer in config', () => { | ||
let port; | ||
|
||
beforeEach(async () => { | ||
port = await getPort(); | ||
}); | ||
|
||
const isWindows = process.platform === 'win32'; | ||
|
||
if (isWindows) { | ||
// TODO fix me on windows | ||
it('compiles without flags', () => { | ||
expect(true).toBe(true); | ||
|
||
console.warn('TODO: fix `serve` test on windows'); | ||
}); | ||
} else { | ||
it('Should pick up the host and port from config', async () => { | ||
const { stdout, stderr } = await runServe([], testPath); | ||
// Should output the correct bundle file | ||
expect(stdout).toContain('main.js'); | ||
expect(stdout).not.toContain('hot/dev-server.js'); | ||
// Runs at correct host and port | ||
expect(stdout).toContain('http://0.0.0.0:1234'); | ||
expect(stderr).toBeFalsy(); | ||
}); | ||
|
||
it('Port flag should override the config port', async () => { | ||
const { stdout, stderr } = await runServe(['--port', port], testPath); | ||
// Should output the correct bundle file | ||
expect(stdout).toContain('main.js'); | ||
expect(stdout).not.toContain('hot/dev-server.js'); | ||
// Runs at correct host and port | ||
expect(stdout).toContain(`http://0.0.0.0:${port}`); | ||
expect(stderr).toBeFalsy(); | ||
}); | ||
|
||
it('Passing hot flag works alongside other server config', async () => { | ||
const { stdout, stderr } = await runServe(['--port', port, '--hot'], testPath); | ||
// Should output the correct bundle file | ||
expect(stdout).toContain('main.js'); | ||
// HMR is being used | ||
expect(stdout).toContain('hot/dev-server.js'); | ||
// Runs at correct host and port | ||
expect(stdout).toContain(`http://0.0.0.0:${port}`); | ||
expect(stderr).toBeFalsy(); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
mode: 'development', | ||
devtool: false, | ||
devServer: { | ||
port: 1234, | ||
host: '0.0.0.0', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters