Skip to content

Commit

Permalink
feat!: update mocha, playwright and others, fix sourcemaps (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed May 16, 2022
1 parent 552d319 commit b6852a4
Show file tree
Hide file tree
Showing 9 changed files with 676 additions and 887 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@
"camelcase": "^6.3.0",
"chokidar": "^3.5.3",
"cpy": "^9.0.1",
"esbuild": "0.14.27",
"esbuild": "0.14.39",
"events": "^3.3.0",
"globby": "^13.1.1",
"kleur": "^4.1.4",
"lilconfig": "^2.0.3",
"lilconfig": "^2.0.5",
"lodash": "^4.17.21",
"merge-options": "^3.0.4",
"nanoid": "^3.3.1",
"nanoid": "^3.3.4",
"ora": "^6.1.0",
"p-wait-for": "4.1.0",
"path-browserify": "^1.0.1",
"playwright-core": "1.20.0",
"playwright-core": "1.22.0",
"polka": "^0.5.2",
"premove": "^4.0.0",
"process": "^0.11.10",
Expand All @@ -73,23 +73,23 @@
"source-map": "0.6.1",
"stream-browserify": "^3.0.0",
"strip-ansi": "^7.0.0",
"tape": "^5.5.2",
"tempy": "^2.0.0",
"tape": "^5.5.3",
"tempy": "^3.0.0",
"test-exclude": "^6.0.0",
"v8-to-istanbul": "^8.1.1"
"v8-to-istanbul": "^9.0.0"
},
"devDependencies": {
"@types/mocha": "^9.1.0",
"@types/mocha": "^9.1.1",
"@types/polka": "^0.5.4",
"benchmark": "^2.1.4",
"copyfiles": "^2.4.1",
"debug": "^4.3.4",
"delay": "^5.0.0",
"execa": "^6.1.0",
"hd-scripts": "^1.1.1",
"mocha": "^9.2.2",
"hd-scripts": "^1.1.2",
"mocha": "^10.0.0",
"simple-git-hooks": "^2.6.1",
"typescript": "^4.6.2",
"typescript": "^4.6.4",
"uvu": "^0.5.3",
"zora": "^5.0.3"
},
Expand Down
14 changes: 7 additions & 7 deletions src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { mkdirSync } from 'fs'
import path from 'path'
import ora from 'ora'
import tempy from 'tempy'
import { nanoid } from 'nanoid'
import { temporaryDirectory } from 'tempy'
import { premove } from 'premove/sync'
import {
redirectConsole,
Expand Down Expand Up @@ -65,12 +65,12 @@ export class Runner {
this.options = merge(defaultOptions, options)
/** @type {import('polka').Polka["server"] | undefined} */
this.server = undefined
this.dir = /** @type {string} */ (
mkdirSync(path.join(__dirname, '../.tmp', nanoid()), {
recursive: true,
})
)
this.browserDir = tempy.directory()

this.dir = path.join(__dirname, '../.tmp', nanoid())
mkdirSync(this.dir, {
recursive: true,
})
this.browserDir = temporaryDirectory()
this.url = ''
this.stopped = false
this.watching = false
Expand Down
2 changes: 1 addition & 1 deletion src/setup-mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable no-undef */

// mocha library itself, to have it set up on global
import mocha from 'mocha/mocha-es2018.js'
import mocha from 'mocha/mocha.js'

const { allowUncaught, bail, reporter, timeout, color, ui, grep } =
process.env.PW_TEST.runnerOptions
Expand Down
4 changes: 2 additions & 2 deletions src/utils/build-sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path'
import { build } from 'esbuild'
import mergeOptions from 'merge-options'
import { fileURLToPath } from 'url'
import tempy from 'tempy'
import { temporaryWriteSync } from 'tempy'

const merge = mergeOptions.bind({
ignoreUndefined: true,
Expand Down Expand Up @@ -40,7 +40,7 @@ self.addEventListener('activate', (event) => {
import "${path.join(runner.options.cwd, entry).replace(/\\/g, '/')}"
`
const entryPoint = tempy.writeSync(content, { extension: 'js' })
const entryPoint = temporaryWriteSync(content, { extension: 'js' })
/** @type {ESBuildPlugin} */
const watchPlugin = {
name: 'watcher',
Expand Down
19 changes: 15 additions & 4 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function globFiles(cwd, patterns) {
/**
* Find files
*
* @param {Object} options
* @param {object} options
* @param {string} options.cwd
* @param {string[]} options.extensions
* @param {string[]} options.filePatterns
Expand All @@ -124,7 +124,7 @@ function findFiles({ cwd, extensions, filePatterns }) {
/**
* Find the tests files
*
* @param {Object} options
* @param {object} options
* @param {string} options.cwd
* @param {string[]} options.extensions
* @param {string[]} options.filePatterns
Expand Down Expand Up @@ -251,7 +251,7 @@ export async function getPw(browserName) {
}

// @ts-ignore
const { registry } = await import('playwright-core/lib/utils/registry')
const { registry } = await import('playwright-core/lib/server')
const api = await import('playwright-core')
const browser = registry.findExecutable(browserName)

Expand Down Expand Up @@ -384,6 +384,7 @@ require('${require
contents: infileContent,
resolveDir: runner.options.cwd,
},
// sourceRoot: runner.dir,
bundle: true,
sourcemap: 'inline',
plugins: [nodePlugin, watchPlugin],
Expand All @@ -392,6 +393,7 @@ require('${require
define: {
global: 'globalThis',
PW_TEST_SOURCEMAP: runner.options.debug ? 'false' : 'true',
PW_TEST_SOURCEMAP_PATH: JSON.stringify(runner.dir),
},
}
await esbuild.build(merge(defaultOptions, config, runner.options.buildConfig))
Expand Down Expand Up @@ -420,7 +422,16 @@ export async function createCov(runner, coverage, file) {

if (filePath.includes(file)) {
// @ts-ignore
const converter = new V8ToIstanbul(filePath, 0, { source: entry.source })
const converter = new V8ToIstanbul(
filePath,
0,
{
source: entry.source,
}
// (path) => {
// return !f.has(path)
// }
)

// eslint-disable-next-line no-await-in-loop
await converter.load()
Expand Down
11 changes: 7 additions & 4 deletions src/vendor/source-map-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ function supportRelativeURL(file, url, tweak) {
)
}
if (tweak && PW_TEST_SOURCEMAP === true) {
return 'file://' + resolve(dir.slice(protocol.length), url)
return resolve(PW_TEST_SOURCEMAP_PATH, url)
// return PW_TEST_SOURCEMAP_PATH + resolve(dir.slice(protocol.length), url)
}

return protocol + resolve(dir.slice(protocol.length), url)
Expand Down Expand Up @@ -185,7 +186,8 @@ function retrieveSourceMapURL(source) {

// Get the URL of the source map
fileData = retrieveFile(source)
const re = /(?:\/\/[@#][\s]*sourceMappingURL=([^\s'"]+)[\s]*$)|(?:\/\*[@#][\s]*sourceMappingURL=([^\s*'"]+)[\s]*(?:\*\/)[\s]*$)/gm
const re =
/(?:\/\/[@#][\s]*sourceMappingURL=([^\s'"]+)[\s]*$)|(?:\/\*[@#][\s]*sourceMappingURL=([^\s*'"]+)[\s]*(?:\*\/)[\s]*$)/gm
// Keep executing the search to find the *last* sourceMappingURL to avoid
// picking up sourceMappingURLs from comments, strings, etc.
let lastMatch, match
Expand Down Expand Up @@ -225,7 +227,7 @@ retrieveMapHandlers.push((source) => {
sourceMappingURL = source
} else {
// Support source map URLs relative to the source URL
sourceMappingURL = supportRelativeURL(source, sourceMappingURL)
sourceMappingURL = supportRelativeURL(source, sourceMappingURL, true)
sourceMapData = retrieveFile(sourceMappingURL)
}

Expand Down Expand Up @@ -463,7 +465,8 @@ function wrapCallSite(frame, state) {
// Header removed in node at ^10.16 || >=11.11.0
// v11 is not an LTS candidate, we can just test the one version with it.
// Test node versions for: 10.16-19, 10.20+, 12-19, 20-99, 100+, or 11.11
const noHeader = /^v(10\.1[6-9]|10\.[2-9][0-9]|10\.[0-9]{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/
const noHeader =
/^v(10\.1[6-9]|10\.[2-9][0-9]|10\.[0-9]{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/
const headerLength = noHeader.test(process.version) ? 0 : 62

if (
Expand Down
3 changes: 1 addition & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('mocha', function () {
// eslint-disable-next-line unicorn/prefer-json-parse-buffer
fs.readFileSync('.nyc_output/coverage-pw.json', 'utf8')
)

ok(path.resolve('mocks/test.mocha.js') in cov, 'test coverage')
})

Expand Down Expand Up @@ -197,7 +196,7 @@ describe('zora', () => {
})
})

describe('benchmark', function () {
describe.skip('benchmark', function () {
it('benchmark', async () => {
const proc = await execa('./cli.js', [
'mocks/benchmark.js',
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "hd-scripts/tsconfig.json",
"extends": "./node_modules/hd-scripts/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"module": "ES2022"
Expand Down
Loading

0 comments on commit b6852a4

Please sign in to comment.