Skip to content

Commit

Permalink
CI should fail when something went wrong. (#5779)
Browse files Browse the repository at this point in the history
* Added unit test script wrapper.

* Removed bin-up to make lint-coffee fail.

* Made mocha tests return non-zero value on failure for reporter and runner

* Added empty space to test ci failure.

* remove extra whitespace

* use Promise.delay instead of hand-rolled sleep function

* include root-level tests

* exit with number of failures
  • Loading branch information
sainthkh authored and chrisbreiding committed Nov 27, 2019
1 parent e313f8c commit e19bcc0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"test-s3-api": "node -r ./packages/coffee/register -r ./packages/ts/register scripts/binary/s3-api-demo.ts",
"test-scripts": "mocha -r packages/coffee/register -r packages/ts/register --reporter spec 'scripts/unit/**/*spec.js'",
"test-scripts-watch": "npm run test-scripts -- --watch --watch-extensions 'ts,js,coffee'",
"test-unit": "node ./scripts/test-unit",
"watch": "npm run all watch"
},
"husky": {
Expand Down
2 changes: 1 addition & 1 deletion packages/reporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint": "bin-up eslint --fix lib/*.js src/*.js* src/**/*.js*",
"preclean": "npm run check-deps-pre",
"pretest": "npm run check-deps-pre",
"test": "mocha 'src/**/*.spec.*'",
"test": "node ../../scripts/test-unit",
"test-watch": "npm run test -- --watch",
"prewatch": "npm run check-deps-pre",
"watch": "npm run build -- --watch --progress"
Expand Down
2 changes: 1 addition & 1 deletion packages/runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"clean-deps": "rm -rf node_modules",
"postinstall": "echo '@packages/runner needs: npm run build'",
"pretest": "npm run check-deps-pre",
"test": "mocha src/**/*.spec.*",
"test": "node ../../scripts/test-unit",
"test-watch": "npm run test -- --watch",
"prewatch": "npm run check-deps-pre",
"watch": "webpack --watch --progress"
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"codecov": "codecov",
"predev": "npm run check-deps-pre",
"dev": "node index.js",
"lint-coffee": "bin-up coffeelint test/*.coffee test/unit/*.coffee test/integration/*.coffee",
"lint-coffee": "../../node_modules/.bin/coffeelint test/*.coffee test/unit/*.coffee test/integration/*.coffee",
"prerepl": "npm run check-deps-pre",
"repl": "node repl.js",
"prestart": "npm run check-deps-pre",
Expand Down
32 changes: 32 additions & 0 deletions scripts/test-unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This file exists because mocha doesn't return non-zero value when there is a failed test.
// When https://github.com/mochajs/mocha/issues/3893 is fixed, it will be removed.

const { spawn } = require('child_process')
const Promise = require('bluebird')

// Test result on console.
let log = ''
const proc = spawn(`node`, ['./node_modules/.bin/mocha', 'src/**/*.spec.*'], {})

proc.stdout.on('data', (data) => {
log += data
})

proc.stdout.on('end', async () => {
await Promise.delay(500)

const result = log.match(/\d+ passing.*\n\s*(\d+) failing/)
const numFailing = result && parseInt(result[1], 10)

if (!isNaN(numFailing)) {
process.exit(numFailing)
}

process.exit(0)
})

// Show result on console.
spawn(`node`, ['./node_modules/.bin/mocha', '"src/*.spec.*" "src/**/*.spec.*"'], {
stdio: 'inherit',
shell: true,
})

4 comments on commit e19bcc0

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e19bcc0 Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.7.0/win32-ia32/appveyor-develop-e19bcc038a6da3ed0255284881c43622b7d25c01-29164892/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.7.0/win32-ia32/appveyor-develop-e19bcc038a6da3ed0255284881c43622b7d25c01-29164892/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e19bcc0 Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.7.0/win32-x64/appveyor-develop-e19bcc038a6da3ed0255284881c43622b7d25c01-29164892/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.7.0/win32-x64/appveyor-develop-e19bcc038a6da3ed0255284881c43622b7d25c01-29164892/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e19bcc0 Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.7.0/linux-x64/circle-develop-e19bcc038a6da3ed0255284881c43622b7d25c01-200653/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.7.0/circle-develop-e19bcc038a6da3ed0255284881c43622b7d25c01-200622/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e19bcc0 Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.7.0/darwin-x64/circle-develop-e19bcc038a6da3ed0255284881c43622b7d25c01-200662/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.7.0/circle-develop-e19bcc038a6da3ed0255284881c43622b7d25c01-200590/cypress.tgz

Please sign in to comment.