Skip to content

Commit

Permalink
refactor: improved polyfill and ponyfill tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lquixada committed Apr 29, 2023
1 parent a3c09c2 commit 644c419
Show file tree
Hide file tree
Showing 22 changed files with 162 additions and 152 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.reports
*.log
dist
test.ponyfill.js
test.polyfill.js
ponyfill.bundle.js
polyfill.bundle.js

# OSX
#
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
],
"ignore": [
"/dist/",
"api.spec.js",
"bundle.js",
"test.js",
"test.*.js",
"api.spec.js",
"*.bundle.js",
"*.ts"
]
},
Expand Down
2 changes: 1 addition & 1 deletion test/module-system/node.cjs/run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
npx webpack --config $(dirname "$0")/webpack.config.js &&
npx mocha $(dirname "$0")/test.*.js
npx mocha $(dirname "$0")/*.bundle.js
2 changes: 1 addition & 1 deletion test/module-system/node.cjs/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = ['polyfill', 'ponyfill'].map(method => ({
entry: [path.join(__dirname, '..', '..', 'setup', 'node.env.js'), path.join(__dirname, `${method}.js`)],
output: {
path: __dirname,
filename: `test.${method}.js`
filename: `${method}.bundle.js`
},
stats: 'none'
}))
2 changes: 1 addition & 1 deletion test/module-system/node.esm/run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
npx webpack --config $(dirname "$0")/webpack.config.js &&
npx mocha $(dirname "$0")/test.*.js
npx mocha $(dirname "$0")/*.bundle.js
2 changes: 1 addition & 1 deletion test/module-system/node.esm/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = ['polyfill', 'ponyfill'].map(method => ({
entry: [path.join(__dirname, '..', '..', 'setup', 'node.env.js'), path.join(__dirname, `${method}.js`)],
output: {
path: __dirname,
filename: `test.${method}.js`
filename: `${method}.bundle.js`
},
stats: 'none'
}))
35 changes: 35 additions & 0 deletions test/module-system/web.cjs/polyfill.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="../../../node_modules/mocha/mocha.css" rel="stylesheet" />
</head>

<body>
<div id="mocha"></div>

<script src="../../../node_modules/chai/chai.js"></script>
<script src="../../../node_modules/mocha/mocha.js"></script>

<script src="../../setup/browser.env.js"></script>
<script src="../../module-system/module.spec.js"></script>
<script src="./polyfill.bundle.js"></script>

<script>
if (/globals=off/.test(location.search)) {
describe('Browser:Polyfill:Require:Webpack', () => {
addModuleSuite({ fetch, Request, Response, Headers })
addPolyfillSuite({ fetch })
})
} else {
describe('Browser:Native:Require:Webpack', () => {
addModuleSuite({ fetch, Request, Response, Headers })
addNativeSuite({ fetch })
})
}

mocha.checkLeaks()
mocha.run()
</script>
</body>
</html>
16 changes: 0 additions & 16 deletions test/module-system/web.cjs/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
require('../../../polyfill')
const { addModuleSuite, addPolyfillSuite, addNativeSuite } = require('../module.spec')

if (/globals=off/.test(location.search)) {
describe('Browser:Polyfill:Require:Webpack', () => {
addModuleSuite({ fetch, Request, Response, Headers })
addPolyfillSuite({ fetch })
})
} else {
describe('Browser:Native:Require:Webpack', () => {
addModuleSuite({ fetch, Request, Response, Headers })
addNativeSuite({ fetch })
})
}

mocha.checkLeaks()
mocha.run()
35 changes: 35 additions & 0 deletions test/module-system/web.cjs/ponyfill.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="../../../node_modules/mocha/mocha.css" rel="stylesheet" />
</head>

<body>
<div id="mocha"></div>

<script src="../../../node_modules/chai/chai.js"></script>
<script src="../../../node_modules/mocha/mocha.js"></script>

<script src="../../setup/browser.env.js"></script>
<script src="../../module-system/module.spec.js"></script>
<script src="./ponyfill.bundle.js"></script>

<script>
if (/globals=off/.test(location.search)) {
describe('Browser:Ponyfill:Require:Webpack', () => {
addModuleSuite(namedExports)
addPonyfillSuite({ ...namedExports, defaultExport })
})
} else {
describe('Browser:Native:Require:Webpack', () => {
addModuleSuite(namedExports)
addNativeSuite({ fetch })
})
}

mocha.checkLeaks()
mocha.run()
</script>
</body>
</html>
20 changes: 2 additions & 18 deletions test/module-system/web.cjs/ponyfill.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
const defaultExport = require('../../..')
const namedExports = require('../../..')
const { addModuleSuite, addPonyfillSuite, addNativeSuite } = require('../module.spec')

if (/globals=off/.test(location.search)) {
describe('Browser:Ponyfill:Require:Webpack', () => {
addModuleSuite(namedExports)
addPonyfillSuite({ ...namedExports, defaultExport })
})
} else {
describe('Browser:Native:Require:Webpack', () => {
addModuleSuite(namedExports)
addNativeSuite({ fetch })
})
}

mocha.checkLeaks()
mocha.run()
window.defaultExport = require('../../..')
window.namedExports = require('../../..')
8 changes: 4 additions & 4 deletions test/module-system/web.cjs/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
npx webpack --config $(dirname "$0")/webpack.config.js &&
npx mocha-headless-chrome -f $(dirname "$0")/test.polyfill.html?globals=off &&
npx mocha-headless-chrome -f $(dirname "$0")/test.polyfill.html?globals=on &&
npx mocha-headless-chrome -f $(dirname "$0")/test.ponyfill.html?globals=off &&
npx mocha-headless-chrome -f $(dirname "$0")/test.ponyfill.html?globals=on
npx mocha-headless-chrome -f $(dirname "$0")/polyfill.html?globals=off &&
npx mocha-headless-chrome -f $(dirname "$0")/polyfill.html?globals=on &&
npx mocha-headless-chrome -f $(dirname "$0")/ponyfill.html?globals=off &&
npx mocha-headless-chrome -f $(dirname "$0")/ponyfill.html?globals=on
17 changes: 0 additions & 17 deletions test/module-system/web.cjs/test.polyfill.html

This file was deleted.

17 changes: 0 additions & 17 deletions test/module-system/web.cjs/test.ponyfill.html

This file was deleted.

2 changes: 1 addition & 1 deletion test/module-system/web.cjs/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = ['polyfill', 'ponyfill'].map(method => ({
entry: path.join(__dirname, `${method}.js`),
output: {
path: __dirname,
filename: `test.${method}.js`
filename: `${method}.bundle.js`
},
stats: 'none'
}))
35 changes: 35 additions & 0 deletions test/module-system/web.esm/polyfill.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="../../../node_modules/mocha/mocha.css" rel="stylesheet" />
</head>

<body>
<div id="mocha"></div>

<script src="../../../node_modules/chai/chai.js"></script>
<script src="../../../node_modules/mocha/mocha.js"></script>

<script src="../../setup/browser.env.js"></script>
<script src="../../module-system/module.spec.js"></script>
<script src="./polyfill.bundle.js"></script>

<script>
if (/globals=off/.test(location.search)) {
describe('Browser:Polyfill:Import:Webpack', () => {
addModuleSuite({ fetch, Request, Response, Headers })
addPolyfillSuite({ fetch })
})
} else {
describe('Browser:Native:Import:Webpack', () => {
addModuleSuite({ fetch, Request, Response, Headers })
addNativeSuite({ fetch })
})
}

mocha.checkLeaks()
mocha.run()
</script>
</body>
</html>
16 changes: 0 additions & 16 deletions test/module-system/web.esm/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
import '../../../polyfill'
import { addModuleSuite, addPolyfillSuite, addNativeSuite } from '../module.spec'

if (/globals=off/.test(location.search)) {
describe('Browser:Polyfill:Import:Webpack', () => {
addModuleSuite({ fetch, Request, Response, Headers })
addPolyfillSuite({ fetch })
})
} else {
describe('Browser:Native:Import:Webpack', () => {
addModuleSuite({ fetch, Request, Response, Headers })
addNativeSuite({ fetch })
})
}

mocha.checkLeaks()
mocha.run()
35 changes: 35 additions & 0 deletions test/module-system/web.esm/ponyfill.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="../../../node_modules/mocha/mocha.css" rel="stylesheet" />
</head>

<body>
<div id="mocha"></div>

<script src="../../../node_modules/chai/chai.js"></script>
<script src="../../../node_modules/mocha/mocha.js"></script>

<script src="../../setup/browser.env.js"></script>
<script src="../../module-system/module.spec.js"></script>
<script src="./ponyfill.bundle.js"></script>

<script>
if (/globals=off/.test(location.search)) {
describe('Browser:Ponyfill:Import:Webpack', () => {
addModuleSuite(namedExports)
addPonyfillSuite({ ...namedExports, defaultExport })
})
} else {
describe('Browser:Native:Import:Webpack', () => {
addModuleSuite(namedExports)
addNativeSuite({ fetch })
})
}

mocha.checkLeaks()
mocha.run()
</script>
</body>
</html>
17 changes: 2 additions & 15 deletions test/module-system/web.esm/ponyfill.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
import defaultExport, * as namedExports from '../../..'
import { addModuleSuite, addPonyfillSuite, addNativeSuite } from '../module.spec'

if (/globals=off/.test(location.search)) {
describe('Browser:Ponyfill:Import:Webpack', () => {
addModuleSuite(namedExports)
addPonyfillSuite({ ...namedExports, defaultExport })
})
} else {
describe('Browser:Native:Import:Webpack', () => {
addModuleSuite(namedExports)
addNativeSuite({ fetch })
})
}

mocha.checkLeaks()
mocha.run()
window.defaultExport = defaultExport
window.namedExports = namedExports
8 changes: 4 additions & 4 deletions test/module-system/web.esm/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
npx webpack --config $(dirname "$0")/webpack.config.js &&
npx mocha-headless-chrome -f $(dirname "$0")/test.polyfill.html?globals=off &&
npx mocha-headless-chrome -f $(dirname "$0")/test.polyfill.html?globals=on &&
npx mocha-headless-chrome -f $(dirname "$0")/test.ponyfill.html?globals=off &&
npx mocha-headless-chrome -f $(dirname "$0")/test.ponyfill.html?globals=on
npx mocha-headless-chrome -f $(dirname "$0")/polyfill.html?globals=off &&
npx mocha-headless-chrome -f $(dirname "$0")/polyfill.html?globals=on &&
npx mocha-headless-chrome -f $(dirname "$0")/ponyfill.html?globals=off &&
npx mocha-headless-chrome -f $(dirname "$0")/ponyfill.html?globals=on
18 changes: 0 additions & 18 deletions test/module-system/web.esm/test.polyfill.html

This file was deleted.

17 changes: 0 additions & 17 deletions test/module-system/web.esm/test.ponyfill.html

This file was deleted.

2 changes: 1 addition & 1 deletion test/module-system/web.esm/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = ['polyfill', 'ponyfill'].map(method => ({
entry: path.join(__dirname, `${method}.js`),
output: {
path: __dirname,
filename: `test.${method}.js`
filename: `${method}.bundle.js`
},
stats: 'none'
}))

0 comments on commit 644c419

Please sign in to comment.