-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: test workability with webpack configs in popular tools and fix a…
…s needed (#21)
- Loading branch information
Showing
6 changed files
with
142 additions
and
22 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
e2e/works-with-webpack-configs-in-popular-tools.spec.ts
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,103 @@ | ||
import { | ||
autoChWebpackProject, | ||
chdir, | ||
depVerWebpack, | ||
depVerWebpackCli, | ||
exec, | ||
execNode, | ||
execWebpack, | ||
expectCommonDirToIncludeAllFilesAnd, | ||
rootPath, | ||
writeFiles, | ||
} from '../support-helpers'; | ||
|
||
it('works with webpack config in facebook/create-react-app', () => { | ||
autoChWebpackProject(); | ||
exec('npm', 'init', '-y'); | ||
exec('npm', 'i', '-D', 'create-react-app'); | ||
exec('npx', 'create-react-app', 'the-app'); | ||
chdir('the-app'); | ||
writeFiles({ | ||
'webpack.config.js': ` | ||
const Plugin = require('${rootPath}'); | ||
const envInQuestion = 'production'; | ||
process.env.NODE_ENV = envInQuestion; | ||
const webpackConfig = require('react-scripts/config/webpack.config')(envInQuestion); | ||
webpackConfig.entry = './src/server.js'; | ||
webpackConfig.plugins = webpackConfig.plugins.filter( | ||
(p) => !['HtmlWebpackPlugin', 'WebpackManifestPlugin'].includes(p.constructor.name) | ||
); | ||
webpackConfig.plugins.push(new Plugin()); | ||
module.exports = webpackConfig; | ||
`, | ||
'src/server.js': ` | ||
import { renderToString } from 'react-dom/server'; | ||
import App from './App'; | ||
console.log(renderToString(<App />)); | ||
`, | ||
}); | ||
exec('npm', 'i', `webpack@${depVerWebpack}`, `webpack-cli@${depVerWebpackCli}`); | ||
expect(execWebpack().status).toBe(0); | ||
expectCommonDirToIncludeAllFilesAnd({ | ||
'build/App.js': (t) => expect(t).toInclude('Learn React'), | ||
'build/logo.svg': (t) => expect(t).toInclude('static/media/logo'), | ||
'build/server.js': (t) => | ||
expect(t).not.toIncludeAnyMembers(['Learn React', 'static/media/logo']), | ||
}); | ||
const { stdout, status } = execNode('build/server.js'); | ||
expect(status).toBe(0); | ||
expect(stdout).toIncludeMultiple(['Learn React', 'static/media/logo']); | ||
}); | ||
|
||
it('works with webpack config in vue/vue-cli', () => { | ||
autoChWebpackProject(); | ||
exec('npm', 'init', '-y'); | ||
exec('npm', 'i', '-D', '@vue/cli'); | ||
exec('npx', 'vue', 'create', '-d', '-m', 'npm', 'the-app'); | ||
chdir('the-app'); | ||
writeFiles({ | ||
'webpack.config.js': ` | ||
const Plugin = require('${rootPath}'); | ||
const envInQuestion = 'production'; | ||
process.env.NODE_ENV = envInQuestion; | ||
const webpackConfig = require('@vue/cli-service/webpack.config'); | ||
webpackConfig.entry = './src/server.js'; | ||
webpackConfig.plugins = webpackConfig.plugins.filter( | ||
(p) => !['HtmlWebpackPlugin'].includes(p.constructor.name) | ||
); | ||
webpackConfig.plugins.push(new Plugin()); | ||
module.exports = webpackConfig; | ||
`, | ||
'src/server.js': ` | ||
import { createSSRApp } from 'vue'; | ||
import { renderToString } from 'vue/server-renderer'; | ||
import App from './App.vue'; | ||
const app = createSSRApp(App); | ||
renderToString(app).then(console.log); | ||
`, | ||
}); | ||
exec('npm', 'i', `webpack@${depVerWebpack}`, `webpack-cli@${depVerWebpackCli}`); | ||
expect(execWebpack().status).toBe(0); | ||
expectCommonDirToIncludeAllFilesAnd({ | ||
'dist/App.vue': (t) => expect(t).toInclude('Vue.js App'), | ||
'dist/assets/logo.png': (t) => expect(t).toInclude('data:image/png;base64'), | ||
'dist/server.js': (t) => | ||
expect(t).not.toIncludeAnyMembers(['Vue.js App', 'data:image/png;base64']), | ||
}); | ||
const { stdout, status } = execNode('dist/server.js'); | ||
expect(status).toBe(0); | ||
expect(stdout).toIncludeMultiple(['Vue.js App', 'data:image/png;base64']); | ||
}); |
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
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