From df379277a73e3194d1cb89e0851eb5b67e6a8159 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Thu, 7 Apr 2016 21:17:55 +0200 Subject: [PATCH 01/12] Test: Remove legacy test runner --- Makefile | 4 +-- bin/run-all-tests | 87 ----------------------------------------------- bin/run-tests | 13 ------- circle.yml | 5 --- 4 files changed, 1 insertion(+), 108 deletions(-) delete mode 100755 bin/run-all-tests delete mode 100755 bin/run-tests diff --git a/Makefile b/Makefile index 890328f900a55..3d5401b4e3523 100644 --- a/Makefile +++ b/Makefile @@ -93,12 +93,10 @@ node_modules: package.json | node-version @$(NPM) install @touch node_modules -# run `make test` in all discovered Makefiles test: build @npm run test-client @npm run test-server - @npm run test-test - @$(BIN)/run-all-tests + @npm run test-tests lint: node_modules/eslint node_modules/eslint-plugin-react node_modules/babel-eslint mixedindentlint @$(NPM) run lint diff --git a/bin/run-all-tests b/bin/run-all-tests deleted file mode 100755 index 75b8b63bb8aab..0000000000000 --- a/bin/run-all-tests +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/bash - -BASEDIR=$(dirname $0) -FAILED=0 -FAILED_ROUTES=() -RED='\033[0;31m' -BLUE='\033[0;34m' -NO_COLOR='\033[0m' - -if [ "${MULTICORE}" = 1 ]; then - CORES=${CORES:-} -else - CORES=1 -fi - - -# print as many equal signs as the terminal is wide -print_horizontal_rule() { - printf "%$(tput cols)s\n" | tr " " "=" -} - - -__count_core_items() { - echo $(cat /proc/cpuinfo | grep "$1" | sort -u | wc -l) -} - -get_cores__linux() { - local cpus=$(__count_core_items "physical id") - local cores=$(__count_core_items "core id") - echo $((cpus * cores)) -} - -get_core_count() { - if [ -z "${CORES}" ]; then - local cores=1 - # OSX - which sysctl &>/dev/null && cores=$(sysctl -n hw.physicalcpu) - # Unix - test -f /proc/cpuinfo && cores=$(get_cores__linux) - echo $cores - else - echo ${CORES} - fi -} - -__print_usage() { - printf "$BLUE" - echo " -*----------------------------------------------------------------------------------------* -| Experimental parallel testing available | -| Usage: | -| export MULTICORE=1 to enable experimental parallel testing. | -| export CORES=4 to control the number of cores used. Leave unset to utilize all cores. | -*----------------------------------------------------------------------------------------* -" - printf "$NO_COLOR" -} - -run_test_fast() { - echo > .test.log - local cores=$(get_core_count) - echo "Using $cores cores" 1>&2 - __print_usage - xargs -P"${cores}" -I % /bin/bash -c '"$1"/run-tests "$2" || (echo "$2" >> .test.log && false)' -- "${BASEDIR}" % - local exitcode=$? - if [ "$exitcode" -ne 0 ]; then - printf "$RED" - echo "These tests have failed:" - cat .test.log | xargs -I % dirname % | xargs /bin/bash -c 'echo $(cd $(dirname "$1") && pwd)/$(basename "$1")' -- - printf "$NO_COLOR" - echo - else - echo "ALL SYSTEMS GO" - fi - rm -f .test.log - exit "$exitcode" -} - -__cleanup() { - echo Cleaning up - rm -f .test.log -} - -trap __cleanup SIGINT SIGTERM - -# Run all tests -find {$BASEDIR/../client,$BASEDIR/../server} -name Makefile | run_test_fast diff --git a/bin/run-tests b/bin/run-tests deleted file mode 100755 index 7ada85b924865..0000000000000 --- a/bin/run-tests +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -NODE_ENV="test" - -RESULT=0 -for makefile in "$@"; do - cat "$makefile" | grep test: > /dev/null - if [[ $? -eq 0 ]]; then - make -C "$(dirname "$makefile")" --no-print-directory test 2>&1; - RESULT=$(($RESULT+$?)); - fi -done -exit $RESULT; diff --git a/circle.yml b/circle.yml index 409d1b621f2ec..1b95fec3a5522 100644 --- a/circle.yml +++ b/circle.yml @@ -13,11 +13,6 @@ test: - client/**/*.jsx - server/**/*.js - server/**/*.jsx - - NODE_ENV=test ./bin/run-tests: - parallel: true - files: - - client/**/Makefile - - server/**/Makefile - MOCHA_FILE=./test-results-client.xml npm run test-client -- --reporter=mocha-junit-reporter: parallel: true files: From 5cd2ab69141ce24dfc032a27c7b6852a9d71d062 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Thu, 7 Apr 2016 21:54:00 +0200 Subject: [PATCH 02/12] Test: Improve the way npm test and make test are configured --- Makefile | 4 +--- package.json | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3d5401b4e3523..89ed54ce763c0 100644 --- a/Makefile +++ b/Makefile @@ -94,9 +94,7 @@ node_modules: package.json | node-version @touch node_modules test: build - @npm run test-client - @npm run test-server - @npm run test-tests + @$(NPM) test lint: node_modules/eslint node_modules/eslint-plugin-react node_modules/babel-eslint mixedindentlint @$(NPM) run lint diff --git a/package.json b/package.json index 1da3c58486308..c66d5aeca48db 100644 --- a/package.json +++ b/package.json @@ -122,7 +122,7 @@ "npm": "3.8.3" }, "scripts": { - "test": "make test", + "test": "npm run test-client && npm run test-server && npm run test-tests", "test-client": "NODE_ENV=test NODE_PATH=test:client TEST_ROOT=client test/runner.js", "test-server": "NODE_ENV=test NODE_PATH=test:server:client TEST_ROOT=server test/runner.js", "test-test": "NODE_ENV=test NODE_PATH=test:client TEST_ROOT=test test/runner.js", From 77c4451ee6b6ed3b39d05d79c178fd9d9eafd9f6 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 20 Apr 2016 10:48:27 +0200 Subject: [PATCH 03/12] Test: Remove obsolete client/lib/auth-code-request-store Makefile --- client/lib/auth-code-request-store/Makefile | 14 -------------- package.json | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 client/lib/auth-code-request-store/Makefile diff --git a/client/lib/auth-code-request-store/Makefile b/client/lib/auth-code-request-store/Makefile deleted file mode 100644 index b8486419a635c..0000000000000 --- a/client/lib/auth-code-request-store/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -REPORTER ?= spec -NODE_BIN := $(shell npm bin) -MOCHA ?= $(NODE_BIN)/mocha -BASE_DIR := $(NODE_BIN)/../.. -NODE_PATH := test:$(BASE_DIR)/client - -# In order to simply stub modules, add test to the NODE_PATH -test: - @NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers js:babel/register --reporter $(REPORTER) - -test-w: - @NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers js:babel/register --reporter min --watch --growl -b - -.PHONY: test diff --git a/package.json b/package.json index c66d5aeca48db..6275339fe9755 100644 --- a/package.json +++ b/package.json @@ -122,7 +122,7 @@ "npm": "3.8.3" }, "scripts": { - "test": "npm run test-client && npm run test-server && npm run test-tests", + "test": "npm run test-client && npm run test-server && npm run test-test", "test-client": "NODE_ENV=test NODE_PATH=test:client TEST_ROOT=client test/runner.js", "test-server": "NODE_ENV=test NODE_PATH=test:server:client TEST_ROOT=server test/runner.js", "test-test": "NODE_ENV=test NODE_PATH=test:client TEST_ROOT=test test/runner.js", From 48124253ca3ff041afd006657bdf893fe25fb281 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 20 Apr 2016 17:59:36 +0200 Subject: [PATCH 04/12] Test: Drop tests.json for client folder --- test/runner.js | 15 +-------------- test/setup.js | 32 +------------------------------- 2 files changed, 2 insertions(+), 45 deletions(-) diff --git a/test/runner.js b/test/runner.js index 2c1748eb50cf5..25a8fc52a821c 100755 --- a/test/runner.js +++ b/test/runner.js @@ -6,8 +6,7 @@ require( 'babel/register' ); /** * External dependencies */ -const debug = require( 'debug' )( 'test-runner' ), - glob = require( 'glob' ), +const glob = require( 'glob' ), Mocha = require( 'mocha' ), path = require( 'path' ), program = require( 'commander' ); @@ -36,21 +35,9 @@ if ( program.grep ) { mocha.grep( new RegExp( program.grep ) ); } -if ( process.env.CIRCLECI ) { - debug( 'Hello Circle!' ); - // give circle more time by default because containers are slow - // why 10 seconds? a guess. - mocha.suite.timeout( 10000 ); -} - mocha.suite.beforeAll( boot.before ); mocha.suite.afterAll( boot.after ); -// TODO: remove whitelist logic once we migrate client folder -if ( process.env.TEST_ROOT === 'client' ) { - setup.enableWhitelist(); -} - files = program.args; if ( files.length === 0 && ! process.env.CIRCLECI ) { files = glob.sync( process.env.TEST_ROOT + '/**/test/*.@(js|jsx)' ); diff --git a/test/setup.js b/test/setup.js index 96e7042ae6814..5cc3dd94e276a 100644 --- a/test/setup.js +++ b/test/setup.js @@ -1,47 +1,18 @@ /** * External dependencies */ -import debugFactory from 'debug'; import head from 'lodash/head'; import last from 'lodash/last'; import mergeWith from 'lodash/mergeWith'; import reduce from 'lodash/reduce'; import tail from 'lodash/tail'; -const debug = debugFactory( 'test-runner' ), - files = []; -let whitelistConfig; - -function enableWhitelist() { - whitelistConfig = require( 'tests.json' ); -} +const files = []; function addFile( file ) { - if ( whitelistConfig ) { - const pathParts = tail( file.split( '/' ) ); - - if ( ! isFileWhitelisted( whitelistConfig, pathParts ) ) { - debug( `Skipping file: ${file}.` ); - return; - } - } files.push( file ); } -function isFileWhitelisted( config, pathParts ) { - const folder = head( pathParts ); - - if ( config[ folder ] ) { - if ( folder === 'test' && Array.isArray( config[ folder ] ) ) { - return ( config[ folder ].indexOf( getFileName( pathParts ) ) !== false ); - } - - return isFileWhitelisted( config[ folder ], tail( pathParts ) ); - } - - return false; -} - function getConfig() { return reduce( files, ( config, file ) => { const fileConfig = fileToConfig( tail( file.split( '/' ) ) ); @@ -73,7 +44,6 @@ function getFileName( pathParts ) { } module.exports = { - enableWhitelist, addFile, getConfig }; From 0c86b0d5b6be69a7f8ee359f8dafe3e18ad3bb4d Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 20 Apr 2016 18:07:26 +0200 Subject: [PATCH 05/12] Test: Move missed client/components/feature-example test --- client/components/feature-example/makefile | 10 ---------- .../feature-example/test/{test.js => index.js} | 6 ++---- 2 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 client/components/feature-example/makefile rename client/components/feature-example/test/{test.js => index.js} (81%) diff --git a/client/components/feature-example/makefile b/client/components/feature-example/makefile deleted file mode 100644 index e4d7be5fa9312..0000000000000 --- a/client/components/feature-example/makefile +++ /dev/null @@ -1,10 +0,0 @@ -REPORTER ?= spec -NODE_BIN := $(shell npm bin) -MOCHA ?= ../../../node_modules/.bin/mocha -BASE_DIR := $(NODE_BIN)/../.. -NODE_PATH := test:$(BASE_DIR)/client - -test: - @NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers jsx:babel/register --reporter $(REPORTER) - -.PHONY: test diff --git a/client/components/feature-example/test/test.js b/client/components/feature-example/test/index.js similarity index 81% rename from client/components/feature-example/test/test.js rename to client/components/feature-example/test/index.js index 52fd10d6d65c9..41ff31b2be63f 100644 --- a/client/components/feature-example/test/test.js +++ b/client/components/feature-example/test/index.js @@ -1,6 +1,3 @@ - -require( 'lib/react-test-env-setup' )(); - /** * External dependencies */ @@ -19,7 +16,8 @@ describe( 'Feature Example', function() { assert.equal( 1, featureExample.find( '.feature-example' ).length ); } ); - it( 'should contains the passed children wrapped by a feature-example div', function() { + // TODO: fix it + it.skip( 'should contains the passed children wrapped by a feature-example div', function() { const featureExample = shallow(
test
); assert.equal( true, featureExample.contains( '
test
' ) ); } ); From 5e27c193c514d5a933ed4abea5423e59c048b24a Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Thu, 21 Apr 2016 07:47:03 +0200 Subject: [PATCH 06/12] Test: Move missed client/components/button-group test --- circle.yml | 9 - client/components/button-group/makefile | 10 - .../button-group/test/{test.js => index.js} | 15 +- client/tests.json | 605 ------------------ test/runner.js | 2 +- 5 files changed, 7 insertions(+), 634 deletions(-) delete mode 100644 client/components/button-group/makefile rename client/components/button-group/test/{test.js => index.js} (84%) delete mode 100644 client/tests.json diff --git a/circle.yml b/circle.yml index 1b95fec3a5522..4fcf18818007c 100644 --- a/circle.yml +++ b/circle.yml @@ -15,19 +15,10 @@ test: - server/**/*.jsx - MOCHA_FILE=./test-results-client.xml npm run test-client -- --reporter=mocha-junit-reporter: parallel: true - files: - - client/**/test/*.js - - client/**/test/*.jsx - MOCHA_FILE=./test-results-server.xml npm run test-server -- --reporter=mocha-junit-reporter: parallel: true - files: - - server/**/test/*.js - - server/**/test/*.jsx - MOCHA_FILE=./test-results-test.xml npm run test-test -- --reporter=mocha-junit-reporter: parallel: true - files: - - test/test/**/test/*.js - - test/test/**/test/*.jsx post: - mkdir -p $CIRCLE_TEST_REPORTS/junit/ && find . -type f -regex "./test-results.*\.xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;: parallel: true diff --git a/client/components/button-group/makefile b/client/components/button-group/makefile deleted file mode 100644 index e4d7be5fa9312..0000000000000 --- a/client/components/button-group/makefile +++ /dev/null @@ -1,10 +0,0 @@ -REPORTER ?= spec -NODE_BIN := $(shell npm bin) -MOCHA ?= ../../../node_modules/.bin/mocha -BASE_DIR := $(NODE_BIN)/../.. -NODE_PATH := test:$(BASE_DIR)/client - -test: - @NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers jsx:babel/register --reporter $(REPORTER) - -.PHONY: test diff --git a/client/components/button-group/test/test.js b/client/components/button-group/test/index.js similarity index 84% rename from client/components/button-group/test/test.js rename to client/components/button-group/test/index.js index 6c74bd240cd70..21226cc26a9db 100644 --- a/client/components/button-group/test/test.js +++ b/client/components/button-group/test/index.js @@ -1,6 +1,3 @@ - -require( 'lib/react-test-env-setup' )(); - /** * External dependencies */ @@ -11,10 +8,11 @@ import sinon from 'sinon'; describe( 'ButtonGroup', function() { let sandbox, ButtonGroup, Button; + beforeEach( function() { sandbox = sinon.sandbox.create(); - sandbox.stub( console, 'error'); - sandbox.stub( console, 'log'); + sandbox.stub( console, 'error' ); + sandbox.stub( console, 'log' ); ButtonGroup = require( '../index' ); Button = require( 'components/button' ); @@ -22,7 +20,7 @@ describe( 'ButtonGroup', function() { afterEach( function() { sandbox.restore(); - }) + } ); it( 'should have ButtonGroup class', function() { const buttonGroup = shallow( ); @@ -35,9 +33,8 @@ describe( 'ButtonGroup', function() { } ); it( 'should throw an error if any of the children is not a