Skip to content

Commit fe9c95c

Browse files
authoredDec 13, 2021
feat: support esm tests in electron main thread (#921)
Swaps `electron-mocha` for `electron-mocha-main` that lets us run ESM tests in the electron main thread. Running them in the renderer thread is still not possible. Fixes #918
1 parent 670714d commit fe9c95c

File tree

8 files changed

+46
-8
lines changed

8 files changed

+46
-8
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"dependency-check": "^5.0.0-2",
8383
"detective-cjs": "^3.1.1",
8484
"detective-es6": "^2.2.0",
85-
"electron-mocha": "^10.0.0",
85+
"electron-mocha-main": "^11.0.3",
8686
"env-paths": "^2.2.1",
8787
"esbuild": "^0.12.15",
8888
"esbuild-register": "^2.3.0",

‎src/test/browser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ module.exports = async (argv, execaOptions) => {
2828
const files = argv.files.length > 0
2929
? argv.files
3030
: [
31-
'**/*.spec.{js,ts}',
32-
'test/browser.{js,ts}'
31+
'**/*.spec.{js,ts,cjs,mjs}',
32+
'test/browser.{js,ts,cjs,mjs}'
3333
]
3434

3535
// before hook

‎src/test/electron.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const merge = require('merge-options')
1717
module.exports = async (argv, execaOptions) => {
1818
const forwardOptions = argv['--'] ? argv['--'] : []
1919
const watch = argv.watch ? ['--watch'] : []
20-
const files = argv.files.length > 0 ? [...argv.files] : ['test/**/*.spec.{js,ts}']
20+
const files = argv.files.length > 0 ? [...argv.files] : ['test/**/*.spec.{js,ts,mjs,cjs}']
2121
const grep = argv.grep ? ['--grep', argv.grep] : []
2222
const progress = argv.progress ? ['--reporter=progress'] : []
2323
const bail = argv.bail ? ['--bail'] : []

‎src/test/node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ async function testNode (argv, execaOptions) {
3131
const files = argv.files.length > 0
3232
? argv.files
3333
: [
34-
'test/node.{js,ts}',
35-
'test/**/*.spec.{js,ts}'
34+
'test/node.{js,ts,cjs,mjs}',
35+
'test/**/*.spec.{js,ts,cjs,mjs}'
3636
]
3737

3838
const args = [

‎src/test/react-native.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ module.exports = async (argv, execaOptions) => {
2727
const files = argv.files.length > 0
2828
? argv.files
2929
: [
30-
'**/*.spec.{js,ts}',
31-
'test/browser.{js,ts}'
30+
'**/*.spec.{js,ts,cjs,mjs}',
31+
'test/browser.{js,ts,cjs,mjs}'
3232
]
3333

3434
// before hook
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-env mocha */
2+
import { useHerp, useDerp } from '../src/index.js'
3+
4+
describe('esm test', () => {
5+
it('runs an esm test', () => {
6+
useHerp()
7+
useDerp()
8+
})
9+
})

‎test/node.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ require('./dependency-check')
88
require('./utils/echo-server')
99
require('./utils/get-port')
1010
require('./config/user')
11+
require('./test')

‎test/test.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const execa = require('execa')
5+
const { copy } = require('fs-extra')
6+
const { join } = require('path')
7+
const bin = require.resolve('../')
8+
const tempy = require('tempy')
9+
10+
describe('test', () => {
11+
describe('esm', function () {
12+
let projectDir = ''
13+
14+
before(async () => {
15+
projectDir = tempy.directory()
16+
17+
await copy(join(__dirname, 'fixtures', 'esm', 'an-esm-project'), projectDir)
18+
})
19+
20+
it('should test an esm project', async function () {
21+
this.timeout(20 * 1000) // slow ci is slow
22+
23+
await execa(bin, ['test'], {
24+
cwd: projectDir
25+
})
26+
})
27+
})
28+
})

0 commit comments

Comments
 (0)
Please sign in to comment.