Skip to content

Commit

Permalink
chore: fix test script for running locally (#666)
Browse files Browse the repository at this point in the history
* chore: fix test script for running locally

* address review comments

* remove calling process.exit
  • Loading branch information
jahtalab authored Mar 3, 2020
1 parent 89de731 commit fda1002
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
39 changes: 23 additions & 16 deletions dev-utils/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ const { generateNotice } = require('./dep-info')
const PROJECT_DIR = join(__dirname, '../')
const { sauceLabs } = getTestEnvironmentVariables()

let cleanUps = []

function startServersWithCleanups() {
let servers = startTestServers.apply(this, arguments)
cleanUps.push(() => {
servers.map(s => s.close())
})
return servers
}

function runUnitTests(packagePath, startSauceConnect = 'false') {
const karmaConfigFile = join(PROJECT_DIR, packagePath, 'karma.conf.js')
if (startSauceConnect === 'true') {
Expand Down Expand Up @@ -114,13 +124,9 @@ function runSauceTests(packagePath, serve = 'true', ...scripts) {
* we launch the sauce connect tunnel before starting all the saucelab tests
*/

let servers = []
if (serve === 'true') {
servers = startTestServers(join(PROJECT_DIR, packagePath))
startServersWithCleanups(join(PROJECT_DIR, packagePath))
}
cleanUps.push(() => {
servers.map(s => s.close())
})

launchSauceConnect(async sauceConnectProcess => {
if (!sauceLabs) {
Expand Down Expand Up @@ -158,17 +164,18 @@ function runSauceTests(packagePath, serve = 'true', ...scripts) {
})
}

let cleanUps = []
function exitHandler(exitCode) {
console.log('Running cleanups.')
cleanUps.forEach(f => {
try {
f(exitCode)
} catch (e) {
console.error(e)
}
})
cleanUps = []
if (cleanUps.length > 0) {
console.log('Running cleanups:', cleanUps.length)
cleanUps.forEach(f => {
try {
f(exitCode)
} catch (e) {
console.error(e)
}
})
cleanUps = []
}
}

process.on('exit', exitHandler)
Expand All @@ -184,7 +191,7 @@ const scripts = {
runNodeTests,
runBundleTests,
buildE2eBundles,
startTestServers
startTestServers: startServersWithCleanups
}

function runScript() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint": "run-p --silent lint:*",
"lint:js": "eslint . --ext .js,.jsx,.ts",
"lint:license": "node scripts/license-checker",
"test": "npm run build && lerna run test --scope=$SCOPE --no-prefix",
"test": "npm run build && lerna run test --scope=$SCOPE --no-prefix --concurrency=1",
"build": "lerna run build",
"bundlesize": "lerna run build:module && lerna run bundlesize",
"serve": "node ./dev-utils/run-script.js startTestServers",
Expand Down

0 comments on commit fda1002

Please sign in to comment.