Skip to content

Commit

Permalink
feat!: upgrade to webpack5
Browse files Browse the repository at this point in the history
Closes: #15
  • Loading branch information
rvagg committed Dec 8, 2021
1 parent 7cca22c commit 4e99018
Show file tree
Hide file tree
Showing 33 changed files with 87 additions and 58 deletions.
8 changes: 0 additions & 8 deletions lib/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ module.exports = function (env, options, runner) {
path.join(__dirname, '../node_modules')
]
},
node: {
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
dns: 'empty',
child_process: 'empty'
},
module: {
rules: [
{
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@
"dependencies": {
"ansi-colors": "^4.1.1",
"glob": "^7.2.0",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"puppeteer": "^12.0.1",
"raw-loader": "^4.0.2",
"readable-stream": "^3.6.0",
"rimraf": "^3.0.2",
"st": "^3.0.0",
"strip-ansi": "^6.0.0",
"webpack": "^4.46.0",
"webpack-merge": "^4.2.2",
"stream-browserify": "^3.0.0",
"strip-ansi": "^6.0.1",
"webpack": "^5.65.0",
"webpack-merge": "^5.8.0",
"yargs": "^17.3.0"
},
"bin": {
"polendina": "./polendina-cli.js",
"polendina-node": "./polendina-node-cli.js"
},
"scripts": {
"lint": "npx standard",
"lint": "npm_config_yes=true npx standard",
"test:install": "for f in $(cd test/fixtures/; ls); do (cd test/fixtures/$f && grep devDependencies package.json > /dev/null && npm i --no-audit --no-fund --no-package-lock) || true; done",
"test:run": "npx mocha test/test-*.js",
"test:run": "npm_config_yes=true npx mocha test/test-*.js",
"test": "npm run lint && npm run test:install && npm run test:run"
},
"repository": {
Expand Down
20 changes: 18 additions & 2 deletions polendina.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const http = require('http')
const st = require('st')
const rimraf = promisify(require('rimraf'))
const webpack = promisify(require('webpack'))
const merge = require('webpack-merge')
const { merge } = require('webpack-merge')
const puppeteer = require('./lib/puppeteer')

class Polendina {
Expand Down Expand Up @@ -34,9 +34,25 @@ class Polendina {
async build () {
let webpackConfig = require('./lib/webpack.config')(process.env, this._options, this._runnerModule)

if (this._options.runner === 'tape') {
webpackConfig = merge(webpackConfig, {
resolve: {
fallback: {
stream: path.join(__dirname, 'node_modules', 'stream-browserify'),
path: path.join(__dirname, 'node_modules', 'path-browserify')
}
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser'
})
]
})
}

if (this._options.webpackConfig) {
const userConfig = require(path.join(process.cwd(), this._options.webpackConfig))
webpackConfig = merge.smart(webpackConfig, userConfig)
webpackConfig = merge(webpackConfig, userConfig)
}

await fs.mkdir(this.outputDir, { recursive: true })
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/bare-async-failure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"type": "git",
"url": "https://github.com/rvagg/polendina.git"
},
"license": "Apache-2.0"
"license": "Apache-2.0",
"devDependencies": {
"chai": "^4.3.4"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/bare-async-failure/test-1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals WorkerGlobalScope ServiceWorkerGlobalScope */

const assert = require('assert')
const { assert } = require('chai')

module.exports = async function () {
if (typeof ServiceWorkerGlobalScope !== 'undefined' && global instanceof ServiceWorkerGlobalScope) {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/bare-async-failure/test-2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert')
const { assert } = require('chai')
const index = require('./')

module.exports.test1 = async function () {
Expand All @@ -7,5 +7,5 @@ module.exports.test1 = async function () {
}

module.exports.test2 = async function () {
assert.fail('nope', 'faily mcfailface')
assert.fail('faily mcfailface')
}
5 changes: 4 additions & 1 deletion test/fixtures/bare-async/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"type": "git",
"url": "https://github.com/rvagg/polendina.git"
},
"license": "Apache-2.0"
"license": "Apache-2.0",
"devDependencies": {
"chai": "^4.3.4"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/bare-async/test-1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals WorkerGlobalScope ServiceWorkerGlobalScope */

const assert = require('assert')
const { assert } = require('chai')

module.exports = async function () {
if (typeof ServiceWorkerGlobalScope !== 'undefined' && global instanceof ServiceWorkerGlobalScope) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/bare-async/test-2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert')
const { assert } = require('chai')
const index = require('./')

module.exports.test1 = async function () {
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/bare-sync-failure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"type": "git",
"url": "https://github.com/rvagg/polendina.git"
},
"license": "Apache-2.0"
"license": "Apache-2.0",
"devDependencies": {
"chai": "^4.3.4"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/bare-sync-failure/test-1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals WorkerGlobalScope ServiceWorkerGlobalScope */

const assert = require('assert')
const { assert } = require('chai')

if (typeof ServiceWorkerGlobalScope !== 'undefined' && global instanceof ServiceWorkerGlobalScope) {
console.log('testing is in serviceworker')
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/bare-sync-failure/test-2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert')
const { assert } = require('chai')
const index = require('.')

console.log('testing bare fixture')
assert.strictEqual(index, 'bare test fixture')
assert.fail('nope', 'faily mcfailface')
assert.fail('faily mcfailface')
5 changes: 4 additions & 1 deletion test/fixtures/bare-sync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"type": "git",
"url": "https://github.com/rvagg/polendina.git"
},
"license": "Apache-2.0"
"license": "Apache-2.0",
"devDependencies": {
"chai": "^4.3.4"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/bare-sync/test-1.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals WorkerGlobalScope ServiceWorkerGlobalScope */

const assert = require('assert')
const { assert } = require('chai')

if (typeof ServiceWorkerGlobalScope !== 'undefined' && global instanceof ServiceWorkerGlobalScope) {
console.log('testing is in serviceworker')
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/bare-sync/test-2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const assert = require('assert')

const { assert } = require('chai')
const index = require('./')

console.log('testing bare fixture')
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/mocha-failure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"url": "https://github.com/rvagg/polendina.git"
},
"devDependencies": {
"mocha": "^7.0.0"
"mocha": "^7.0.0",
"chai": "^4.3.4"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/mocha-failure/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* globals describe it WorkerGlobalScope ServiceWorkerGlobalScope */
const assert = require('assert')
const { assert } = require('chai')

describe('test suite 1 - worker', () => {
if (typeof ServiceWorkerGlobalScope !== 'undefined' && global instanceof ServiceWorkerGlobalScope) {
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/mocha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"url": "https://github.com/rvagg/polendina.git"
},
"devDependencies": {
"mocha": "^7.0.0"
"mocha": "^7.0.0",
"chai": "^4.3.4"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/mocha/test-1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* globals describe it */

const fixture = require('./')
const assert = require('assert')
const { assert } = require('chai')

describe('test suite 1', () => {
it('test case 1', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/mocha/test-2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals describe it WorkerGlobalScope ServiceWorkerGlobalScope */

const assert = require('assert')
const { assert } = require('chai')

describe('test suite 2 - worker', () => {
if (typeof ServiceWorkerGlobalScope !== 'undefined' && global instanceof ServiceWorkerGlobalScope) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/mocha/test-3.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* globals describe it */

const fixture = require('./')
const assert = require('assert')
const { assert } = require('chai')

describe('test suite 3', () => {
it('test case 1', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/mocha8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"url": "https://github.com/rvagg/polendina.git"
},
"devDependencies": {
"mocha": "^8.0.0"
"mocha": "^8.0.0",
"chai": "^4.3.4"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/mocha8/test-1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* globals describe it */

const fixture = require('./')
const assert = require('assert')
const { assert } = require('chai')

describe('test suite 1', () => {
it('test case 1', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/mocha8/test-2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals describe it WorkerGlobalScope ServiceWorkerGlobalScope */

const assert = require('assert')
const { assert } = require('chai')

describe('test suite 2 - worker', () => {
if (typeof ServiceWorkerGlobalScope !== 'undefined' && global instanceof ServiceWorkerGlobalScope) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/mocha8/test-3.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* globals describe it */

const fixture = require('./')
const assert = require('assert')
const { assert } = require('chai')

describe('test suite 3', () => {
it('test case 1', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/tape/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"url": "https://github.com/rvagg/polendina.git"
},
"devDependencies": {
"tape": "^5.0.1"
"tape": "^5.3.2"
}
}
5 changes: 4 additions & 1 deletion test/fixtures/webpack-merge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"type": "git",
"url": "https://github.com/rvagg/polendina.git"
},
"license": "Apache-2.0"
"license": "Apache-2.0",
"devDependencies": {
"chai": "^4.3.4"
}
}
7 changes: 3 additions & 4 deletions test/fixtures/webpack-merge/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const assert = require('assert')
const qs = require('querystring')
const { assert } = require('chai')

assert.strictEqual(typeof assert.ok, 'function')
console.log('assert.ok() is a function')
assert.strictEqual(typeof qs.parse, 'function')
console.log('querystring.parse() is a function')
assert.strictEqual(WOOP, 'woop') // eslint-disable-line
console.log('WOOP is set')
6 changes: 3 additions & 3 deletions test/fixtures/webpack-merge/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const webpack = require('webpack')

module.exports = {
node: {
querystring: 'empty'
}
plugins: [new webpack.DefinePlugin({ WOOP: '"woop"' })]
}
2 changes: 1 addition & 1 deletion test/test-bare-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ testing bare fixture
✔ test1
✘ test2
`
const expectedStderr = 'AssertionError: \'nope\' undefined \'faily mcfailface\''
const expectedStderr = 'AssertionError: faily mcfailface'

it('should fail in page', async () => {
let { stdout, stderr, code } = await runCli(bareSyncFailureFixture, '--runner=bare-async')
Expand Down
2 changes: 1 addition & 1 deletion test/test-bare-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ testing is WORKER
testing bare fixture
✘ test-2.js
`
const expectedStderr = 'AssertionError: \'nope\' undefined \'faily mcfailface\''
const expectedStderr = 'AssertionError: faily mcfailface'

it('should fail in page', async () => {
let { stdout, stderr, code } = await runCli(bareSyncFailureFixture, '--runner=bare-sync')
Expand Down
4 changes: 2 additions & 2 deletions test/test-polendina-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Took X seconds
const { stdout, stderr, code } = await runCli('bare-sync', bareSyncFailureFixture)
assert.strictEqual(code, 1, 'exited with non-zero exit code')
assert.strictEqual(removeTiming(stdout), expected)
assert.ok(stderr.includes('AssertionError [ERR_ASSERTION]: \'nope\' != \'faily mcfailface\''), 'stderr contains expected output')
assert.ok(stderr.includes('AssertionError: faily mcfailface'), 'stderr contains expected output')
})
})

Expand Down Expand Up @@ -78,6 +78,6 @@ Took X seconds
const { stdout, stderr, code } = await runCli('bare-async', bareAsyncFailureFixture)
assert.strictEqual(code, 1, 'exited with non-zero exit code')
assert.strictEqual(removeTiming(stdout), expected)
assert.ok(stderr.includes('AssertionError [ERR_ASSERTION]: \'nope\' != \'faily mcfailface\''), 'stderr contains expected output')
assert.ok(stderr.includes('AssertionError: faily mcfailface'), 'stderr contains expected output')
})
})
12 changes: 6 additions & 6 deletions test/test-webpack-merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ const webpackMergeFixture = path.join(__dirname, 'fixtures/webpack-merge')

describe('basic webpack-merge', function () {
this.timeout(20000)
it('should run plain', async () => {
it('should run with a custom config', async () => {
const expected = `
assert.ok() is a function
querystring.parse() is a function
WOOP is set
✔ test.js
`
const { stdout, code } = await runCli(webpackMergeFixture, '--runner=bare-sync')
const { stdout, code } = await runCli(webpackMergeFixture, '--runner=bare-sync --webpack-config webpack.config.js')
assert.strictEqual(code, 0, 'exited with zero exit code')
assert.ok(stdout.includes(expected), 'stdout contains expected test output')
assert.ok(stdout.includes('Running bare-sync page tests with Puppeteer'), 'stdout contains expected output for running in page')
})

it('should fail with custom config', async () => {
it('should fail without a custom config', async () => {
const expectedStdout = `
assert.ok() is a function
✘ test.js
`
const expectedStderr = '\'undefined\' === \'function\''
const expectedStderr = 'WOOP is not defined'

const { stdout, stderr, code } = await runCli(webpackMergeFixture, '--runner=bare-sync --webpack-config webpack.config.js')
const { stdout, stderr, code } = await runCli(webpackMergeFixture, '--runner=bare-sync')
assert.strictEqual(code, 1, 'exited with zero exit code')
assert.ok(stdout.includes(expectedStdout), 'stdout contains expected test output')
assert.ok(stderr.includes(expectedStderr), 'stderr contains expected test output')
Expand Down

0 comments on commit 4e99018

Please sign in to comment.