diff --git a/Makefile b/Makefile index a643f0ee5cecae..890328f900a55f 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,7 @@ node_modules: package.json | node-version test: build @npm run test-client @npm run test-server - @npm run test-tests + @npm run test-test @$(BIN)/run-all-tests lint: node_modules/eslint node_modules/eslint-plugin-react node_modules/babel-eslint mixedindentlint diff --git a/circle.yml b/circle.yml index 496bb9c3567744..409d1b621f2eca 100644 --- a/circle.yml +++ b/circle.yml @@ -2,6 +2,9 @@ machine: node: version: 5.10.1 test: + pre: + - NODE_ENV=test make client/config/index.js: + parallel: true override: - npm run lint -- : parallel: true @@ -10,22 +13,22 @@ test: - client/**/*.jsx - server/**/*.js - server/**/*.jsx - - NODE_ENV=test make client/config/index.js && NODE_ENV=test ./bin/run-tests: + - NODE_ENV=test ./bin/run-tests: parallel: true files: - client/**/Makefile - server/**/Makefile - - NODE_ENV=test make client/config/index.js && MOCHA_FILE=./test-results-client.xml npm run test-client -- --reporter=mocha-junit-reporter -w: + - MOCHA_FILE=./test-results-client.xml npm run test-client -- --reporter=mocha-junit-reporter: parallel: true files: - client/**/test/*.js - client/**/test/*.jsx - - NODE_ENV=test make client/config/index.js && MOCHA_FILE=./test-results-server.xml npm run test-server -- --reporter=mocha-junit-reporter -w: + - MOCHA_FILE=./test-results-server.xml npm run test-server -- --reporter=mocha-junit-reporter: parallel: true files: - server/**/test/*.js - server/**/test/*.jsx - - NODE_ENV=test make client/config/index.js && MOCHA_FILE=./test-results-tests.xml npm run test-tests -- --reporter=mocha-junit-reporter -w: + - MOCHA_FILE=./test-results-test.xml npm run test-test -- --reporter=mocha-junit-reporter: parallel: true files: - test/test/**/test/*.js diff --git a/package.json b/package.json index 315926373d3903..1da3c58486308e 100644 --- a/package.json +++ b/package.json @@ -123,9 +123,9 @@ }, "scripts": { "test": "make test", - "test-client": "NODE_ENV=test NODE_PATH=test:client test/runner.js", - "test-server": "NODE_ENV=test NODE_PATH=test:server:client test/runner.js", - "test-tests": "NODE_ENV=test NODE_PATH=test:test/test:client test/runner.js", + "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", "lint": "bin/run-lint" }, "devDependencies": { diff --git a/server/api/Makefile b/server/api/Makefile deleted file mode 100644 index 9799e4d1e8b927..00000000000000 --- a/server/api/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -NODE_BIN := $(shell npm bin) -MOCHA ?= $(NODE_BIN)/mocha -BASE_DIR := $(NODE_BIN)/../.. -NODE_PATH := ../:$(BASE_DIR)/client -COMPILERS ?= js:babel/register -REPORTER ?= spec -UI ?= bdd - -test: - @NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers $(COMPILERS) --reporter $(REPORTER) --ui $(UI) - -.PHONY: test diff --git a/server/api/test/test.js b/server/api/test/test.js index c41628613da96d..6202c9bbeb52c8 100644 --- a/server/api/test/test.js +++ b/server/api/test/test.js @@ -6,23 +6,23 @@ var expect = require( 'chai' ).expect, request = require( 'superagent' ), supertest = require( 'supertest' ); -/** - * Internal dependencies - */ -var config = require( 'config' ), - app = require( '../' )(), - localRequest = supertest( app ); - if ( process.env.NODE_ENV === 'desktop' ) { describe( 'api', function() { - var sandbox = sinon.sandbox.create(); + const sandbox = sinon.sandbox.create(); + let app, config, localRequest; + + before( () => { + config = require( 'config' ); + app = require( '../' )(); + localRequest = supertest( app ); + } ); afterEach( function() { sandbox.restore(); } ); it( 'should return package version', function( done ) { - var version = require( '../../../package.json' ).version + const version = require( '../../../package.json' ).version; localRequest.get( '/version' ) .expect( 200, { version: version }, done ); diff --git a/server/tests.json b/server/tests.json deleted file mode 100644 index 1a62bb8af998f4..00000000000000 --- a/server/tests.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "config": { - "test": [ "parser" ] - }, - "devdocs": { - "test": [ "index" ] - }, - "i18n": { - "test": [ "index" ] - }, - "pages": { - "test": [ "index" ] - } -} diff --git a/test/README.md b/test/README.md index 1a14b49ae6e095..65bdc61b0286fa 100644 --- a/test/README.md +++ b/test/README.md @@ -49,7 +49,7 @@ We provide three single test runners because of different node path rules applie * `server/` folder * `test/` folder -We have an `npm run` script for each of them: `npm run test-client`, `npm run test-server` and `npm run test-tests`. You can pass a filename or set of files to these scripts to isolate your test run to just your set of files. +We have an `npm run` script for each of them: `npm run test-client`, `npm run test-server` and `npm run test-test`. You can pass a filename or set of files to these scripts to isolate your test run to just your set of files. Example for client: @@ -63,7 +63,7 @@ Example for client: > # run single test suite from server folder > npm run test-server server/config/test/parser.js > # run single test suite from test folder -> npm run test-tests test/helpers/use-nock/test/index.js +> npm run test-test test/helpers/use-nock/test/index.js ``` ### How to run specified suite or test-case diff --git a/test/runner.js b/test/runner.js index f79011e8835557..2c1748eb50cf56 100755 --- a/test/runner.js +++ b/test/runner.js @@ -1,18 +1,27 @@ #!/usr/bin/env node +var files; + require( 'babel/register' ); +/** + * External dependencies + */ const debug = require( 'debug' )( 'test-runner' ), - program = require( 'commander' ), + glob = require( 'glob' ), Mocha = require( 'mocha' ), path = require( 'path' ), - boot = require( './boot-test' ), + program = require( 'commander' ); + +/** + * Internal dependencies + */ +const boot = require( './boot-test' ), setup = require( './setup' ); program .usage( '[options] [files]' ) .option( '-R, --reporter ', 'specify the reporter to use', 'spec' ) - .option( '-g, --grep ', 'only run tests matching ' ) - .option( '-w, --whitelist', 'only run whitelisted tests when using a glob' ); + .option( '-g, --grep ', 'only run tests matching ' ); program.name = 'runner'; @@ -27,10 +36,6 @@ if ( program.grep ) { mocha.grep( new RegExp( program.grep ) ); } -if ( program.whitelist ) { - setup.enableWhitelist(); -} - if ( process.env.CIRCLECI ) { debug( 'Hello Circle!' ); // give circle more time by default because containers are slow @@ -41,12 +46,16 @@ if ( process.env.CIRCLECI ) { mocha.suite.beforeAll( boot.before ); mocha.suite.afterAll( boot.after ); -// we could also discover all the tests using a glob? -if ( program.args.length ) { - program.args.forEach( function( file ) { - setup.addFile( file ); - } ); +// 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)' ); } +files.forEach( setup.addFile ); mocha.addFile( path.join( __dirname, 'load-suite.js' ) ); diff --git a/test/setup.js b/test/setup.js index f0c0fcbe3bc2dc..96e7042ae68146 100644 --- a/test/setup.js +++ b/test/setup.js @@ -32,7 +32,7 @@ function isFileWhitelisted( config, pathParts ) { const folder = head( pathParts ); if ( config[ folder ] ) { - if ( folder === 'test' ) { + if ( folder === 'test' && Array.isArray( config[ folder ] ) ) { return ( config[ folder ].indexOf( getFileName( pathParts ) ) !== false ); } @@ -43,16 +43,6 @@ function isFileWhitelisted( config, pathParts ) { } function getConfig() { - if ( ! whitelistConfig && files.length === 0 ) { - // this assumes that there's a tests.json at the root of NODE_PATH - debug( 'No tests provided, loading whitelisted tests config.' ); - return require( 'tests.json' ); - } - - return filesToConfig(); -} - -function filesToConfig() { return reduce( files, ( config, file ) => { const fileConfig = fileToConfig( tail( file.split( '/' ) ) ); @@ -67,7 +57,7 @@ function filesToConfig() { function fileToConfig( pathParts, folderConfig = {} ) { const folder = head( pathParts ); - if ( folder === 'test' ) { + if ( folder === 'test' && pathParts.length === 2 ) { folderConfig[ folder ] = [ getFileName( pathParts ) ]; } else { folderConfig[ folder ] = fileToConfig( tail( pathParts ) ); diff --git a/test/test/tests.json b/test/test/tests.json deleted file mode 100644 index 766d784f3d7b99..00000000000000 --- a/test/test/tests.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "helpers" : { - "use-i18n": { - "test": [ "index" ] - }, - "use-nock": { - "test": [ "index" ] - } - } -}