From 0011bfea8cff2ae90f7cc60565f8dcae03da8294 Mon Sep 17 00:00:00 2001 From: Enishowk Date: Tue, 30 Oct 2018 10:57:26 +0000 Subject: [PATCH] feat(travis/tests): run tests on files that differs from master (#3599) Fixes #2703 --- .travis.yml | 3 +-- package.json | 3 ++- scripts/travis-tests | 45 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100755 scripts/travis-tests diff --git a/.travis.yml b/.travis.yml index b7fe68564..efaba9323 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,5 +21,4 @@ cache: yarn: true script: - - yarn run test - - yarn run test-integration + - yarn run travis-tests diff --git a/package.json b/package.json index 43c51bfdf..bba85378f 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,8 @@ "prepare": "scripts/run-script prepare", "pretest": "eslint --ignore-path .gitignore .", "test": "jest \"^(?!.*\\.integ\\.spec\\.js$)\"", - "test-integration": "jest \".integ\\.spec\\.js$\"" + "test-integration": "jest \".integ\\.spec\\.js$\"", + "travis-tests": "scripts/travis-tests" }, "workspaces": [ "@xen-orchestra/*", diff --git a/scripts/travis-tests b/scripts/travis-tests new file mode 100755 index 000000000..86556324d --- /dev/null +++ b/scripts/travis-tests @@ -0,0 +1,45 @@ +#!/usr/bin/env node + +const { execFileSync, spawnSync } = require('child_process') + +const run = (command, args) => { + const { status } = spawnSync(command, args, { stdio: 'inherit' }) + if (status !== 0) { + process.exit(status) + } +} + +const getFiles = () => + execFileSync( + 'git', + [ + 'diff-index', + '--diff-filter=AM', + '--ignore-submodules', + '--name-only', + 'master', + ], + { encoding: 'utf8' } + ) + .split('\n') + .filter(_ => _ !== '') + +// ----------------------------------------------------------------------------- + +// Travis vars : https://docs.travis-ci.com/user/environment-variables#default-environment-variables. +if (process.env.TRAVIS_PULL_REQUEST !== 'false') { + const files = getFiles().filter(_ => _.endsWith('.js')) + if (files.length !== 0) { + run( + './node_modules/.bin/jest', + [ + '--testRegex=^(?!.*.integ.spec.js$).*.spec.js$', + '--findRelatedTests', + '--passWithNoTests', + ].concat(files) + ) + } +} else { + run('yarn', ['test']) + run('yarn', ['test-integration']) +}