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
49 changes: 49 additions & 0 deletions test/tests/js/Bundle-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import fs from 'fs'
import os from 'os'
import path from 'path'
import vm from 'vm'
import webpack from 'webpack'
import { expect } from 'chai'

import webpackConfig from './../../../webpack/webpack.config'

function build (outputPath) {
const config = {
...webpackConfig,
output: { ...webpackConfig.output, path: outputPath },
optimization: { minimize: false }
}

return new Promise((resolve, reject) => {
webpack(config, (error, stats) => {
if (error) return reject(error)
if (stats.hasErrors()) { return reject(new Error(stats.toString('errors-only'))) }
resolve(path.join(outputPath, config.output.filename))
})
})
}

describe('dist bundle', function () {
this.timeout(60000)

it('can be imported without a DOM (SSR)', async function () {
const outputPath = fs.mkdtempSync(path.join(os.tmpdir(), 'rjv-bundle-'))
try {
const file = await build(outputPath)
const code = fs.readFileSync(file, 'utf8')
const module = { exports: {} }
// a fresh context has no `window` or `document`, like Node during SSR
const context = vm.createContext({
module,
exports: module.exports,
require
})

vm.runInContext(code, context, { filename: file })

expect(module.exports.default).to.be.a('function')
} finally {
fs.rmSync(outputPath, { recursive: true, force: true })
}
})
})
7 changes: 6 additions & 1 deletion webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ const config = {
},
plugins: [],
resolve: {
extensions: ['.js', '.json', '.css', '.scss']
extensions: ['.js', '.json', '.css', '.scss'],
alias: {
// The browser build reads `document` on import, which breaks SSR.
// The default build checks for `document` first, so bundle that one.
'react-textarea-autosize$': require.resolve('react-textarea-autosize')
}
},
module: {
rules: [
Expand Down
Loading