Skip to content

Commit

Permalink
Merge pull request #4673 from Automattic/test/drop-whitelist-files
Browse files Browse the repository at this point in the history
Test: Drop whitelist config for server and test folders
  • Loading branch information
gziolo committed Apr 20, 2016
2 parents 9821447 + 2705965 commit 8b2b773
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 0 additions & 12 deletions server/api/Makefile

This file was deleted.

18 changes: 9 additions & 9 deletions server/api/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
14 changes: 0 additions & 14 deletions server/tests.json

This file was deleted.

4 changes: 2 additions & 2 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
35 changes: 22 additions & 13 deletions test/runner.js
Original file line number Diff line number Diff line change
@@ -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 <name>', 'specify the reporter to use', 'spec' )
.option( '-g, --grep <pattern>', 'only run tests matching <pattern>' )
.option( '-w, --whitelist', 'only run whitelisted tests when using a glob' );
.option( '-g, --grep <pattern>', 'only run tests matching <pattern>' );

program.name = 'runner';

Expand All @@ -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
Expand All @@ -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' ) );

Expand Down
14 changes: 2 additions & 12 deletions test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand All @@ -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( '/' ) ) );

Expand All @@ -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 ) );
Expand Down
10 changes: 0 additions & 10 deletions test/test/tests.json

This file was deleted.

0 comments on commit 8b2b773

Please sign in to comment.