diff --git a/.travis.yml b/.travis.yml index 2e0ad83feeb19003f885ea0faa3f40b26aa857a0..4a564717b3cf3b6dcd655ab4b7f4a313ef9c8ff2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ script: - echo $TRAVIS_OS_NAME - node --version - npm --version - - ./script/safe-test.sh + - npm run test:safe after_success: - if [ "$TRAVIS_OS_NAME" == 'osx' ]; then npm run coverage; fi diff --git a/Dockerfile b/Dockerfile index 31a6f9716851e4c6950ddc3893b7607afd1ce18f..2e04b66dc8db2bf9e0d148423a3bed93d25dc3b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,7 +60,7 @@ RUN npm install \ COPY . . # RUN npm run test:debug -RUN ./script/safe-test.sh +RUN npm run test:safe RUN npm run dist # Loading from node_modules Folders: https://nodejs.org/api/modules.html diff --git a/bin/entrypoint.sh b/bin/entrypoint.sh index b438241ab45c98d92cb86b5623a161923b000b99..bc7d792e87a4f82605fcd7c39e8e119dc8f31e4c 100755 --- a/bin/entrypoint.sh +++ b/bin/entrypoint.sh @@ -32,10 +32,10 @@ function wechaty::errorBotNotFound() { `--volume="$(pwd)":/bot` this will let the container visit your current directory. - + 2. Are you sure your .js/.ts files aren't .js.txt/.ts.txt? - - this could be a problem on new Windows installs (file + + this could be a problem on new Windows installs (file extensions hidden by default). if you still have issue, please have a look at @@ -265,7 +265,7 @@ function main() { test) # WECHATY_LOG=silent npm run test:unit - WECHATY_LOG=silent ./script/safe-test.sh + WECHATY_LOG=silent npm run test:safe ;; # diff --git a/package.json b/package.json index ccf38a89b0037d2901beb47e348293deefcdfc22..8818b5a6538966b31366ffd7203a2c4d7ac56c3d 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "lint:sh": "bash -n bin/*.sh", "sloc": "sloc bin example src test index.ts --details --format cli-table --keys total,source,comment && sloc bin example src test index.ts", "test": "npm run clean && npm run lint && npm run test:unit && npm run test:shell && npm run sloc", + "test:safe": "ts-node script/safe-test", "test:linux": "npm run pretest && parallel ts-node -- ./src/**/*.spec.ts ./test/**/*.spec.ts && npm run posttest", "test:pack": "npm run dist && export TMPDIR=/tmp/wechaty.$$ && npm pack && mkdir $TMPDIR && mv wechaty-*.*.*.tgz $TMPDIR && cp test/fixture/smoke-testing.js $TMPDIR && cd $TMPDIR && npm init -y && npm i wechaty-*.*.*.tgz && node smoke-testing.js", "test:shell": "shellcheck bin/*.sh", diff --git a/script/safe-test.sh b/script/safe-test.sh deleted file mode 100755 index a6386f8b03a18c4820b29599aa437b0e39f8ae02..0000000000000000000000000000000000000000 --- a/script/safe-test.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# -# https://github.com/Chatie/wechaty/issues/1084 -# WebDriver / Puppeteer sometimes will fail(i.e. timeout) with no reason. -# That will cause the unit tests fail randomly. -# So we need to retry again when unit tests fail, -# and treat it's really fail after MAX_RETRY_NUM times. - -MAX_RETRY_NUM=3 - -echo "Safe Test: starting..." - -n=0 -npm test -while ((n < MAX_RETRY_NUM && $? > 0)) -do - ((n++)) - echo "Safe Test: retrying $n times..." - npm test -done diff --git a/script/safe-test.ts b/script/safe-test.ts new file mode 100644 index 0000000000000000000000000000000000000000..827066006a13c842e406b8f5b6e07f9e38d3278d --- /dev/null +++ b/script/safe-test.ts @@ -0,0 +1,52 @@ +#!/usr/bin/env ts-node +/** + * https://github.com/Chatie/wechaty/issues/1084 + * WebDriver / Puppeteer sometimes will fail(i.e. timeout) with no reason. + * That will cause the unit tests fail randomly. + * So we need to retry again when unit tests fail, + * and treat it's really fail after MAX_RETRY_NUM times. + */ +import { spawn } from 'child_process' + +const MAX_RETRY_NUM = 1 + +async function main(): Promise { + console.log('Safe Test: starting...') + + let round = 0 + let succ = false + do { + console.log(`Safe Test: running for round #${round}`) + succ = await npmTest() + if (succ) { // success! + console.log(`Safe Test: successed at round #${round}!`) + return 0 + } + } while (round++ < MAX_RETRY_NUM) + return 1 // fail finally :( +} + +async function npmTest() { + const child = spawn( + 'npm', + [ + 'test', + ], + { + stdio: 'inherit', + }, + ) + return new Promise((resolve, reject) => { + child.once('exit', code => + code === 0 ? resolve(true) : resolve(false), + ) + child.once('error', reject) + }) +} + +main() +.then(process.exit) +.catch(e => { + console.error(e) + process.exit(1) +}) diff --git a/src/puppet-web/bridge.spec.ts b/src/puppet-web/bridge.spec.ts index a36c6b3000c290a752bad00cfc78398b5c5bea9d..fff5fc69afffb65847580ecf8bbf19cccfd6caed 100755 --- a/src/puppet-web/bridge.spec.ts +++ b/src/puppet-web/bridge.spec.ts @@ -177,5 +177,4 @@ test('clickSwitchAccount()', async t => { t.equal(clicked, false, 'should no button found') }) - })