Skip to content

Commit

Permalink
Scripts: New scripts package containing test command (#62)
Browse files Browse the repository at this point in the history
* Scripts: initial commit with scripts package containing test command

* Publish

 - @wordpress/[email protected]

* Scripts: Minor changes before publishing to npm
  • Loading branch information
gziolo authored Jan 25, 2018
1 parent 3d50441 commit 7ee6367
Show file tree
Hide file tree
Showing 9 changed files with 5,490 additions and 3,403 deletions.
3,825 changes: 432 additions & 3,393 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"check-node-version": "^3.1.1",
"codecov": "^2.2.0",
"glob": "^7.1.2",
"jest": "^22.0.3",
"lerna": "^2.5.1",
"mkdirp": "^0.5.1",
"rimraf": "^2.6.1"
Expand All @@ -30,10 +29,10 @@
"prebuild": "check-node-version --package",
"build": "node ./scripts/build.js",
"postinstall": "lerna bootstrap --hoist && npm run build",
"test": "jest",
"test:coverage": "jest --coverage",
"test:coverage-ci": "jest --coverage && codecov",
"test:watch": "jest --watch",
"test": "./packages/scripts/bin/wp-scripts.js test",
"test:coverage": "npm run test -- --coverage",
"test:coverage-ci": "npm run test -- --coverage && codecov",
"test:watch": "npm run test -- --watch",
"publish:dev": "npm run build-clean && npm run build && lerna publish --npm-tag next",
"publish:prod": "npm run build-clean && npm run build && lerna publish"
}
Expand Down
1 change: 1 addition & 0 deletions packages/jest-console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "WordPress",
"license": "GPL-2.0-or-later",
"keywords": [
"wordpress",
"jest",
"matchers",
"console"
Expand Down
39 changes: 39 additions & 0 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# @wordpress/scripts

A collection of JS scripts for WordPress development.

## Installation

Install the module

```bash
npm install @wordpress/scripts --save-dev
```

## Setup

This is a CLI and exposes a binary called `wp-scripts` so you can call it directly. However this module is designed to be configured using the `scripts` section in the `package.json` file of your project. Example configuration:
```json
{
"scripts": {
"test": "wp-scripts",
"test:help": "wp-scripts --help",
"test:watch": "wp-scripts --watch"
}
}
```

This is how you execute those scripts using the presented setup:
* `npm run test` or `npm test` - runs all unit tests.
* `npm run test:help` - prints all available options to configure unit tests runner.
* `npm run test:watch` - runs all unit tests in the watch mode.

## Available Scripts

### `wp-scripts test`

Launches the test runner. It uses [Jest](https://facebook.github.io/jest/) behind the scenes and you are able to utilize all of its [CLI options](https://facebook.github.io/jest/docs/en/cli.html). You can also run `./node_modules/.bin/wp-scripts --help` or `npm run test:help` (if you use `package.json` setup shared above) to view all of the available options.

## Inspiration

This is inspired by [react-scripts](https://www.npmjs.com/package/react-scripts) and [kcd-scripts](https://www.npmjs.com/package/kcd-scripts).
38 changes: 38 additions & 0 deletions packages/scripts/bin/wp-scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env node

const spawn = require( 'cross-spawn' );

const allowedScripts = [ 'test' ];
const [ scriptName, ...nodeArgs ] = process.argv.slice( 2 );

if ( allowedScripts.indexOf( scriptName ) === -1 ) {
console.log( 'Unknown script "' + scriptName + '".' );
console.log( 'Perhaps you need to update @wordpress/scripts?' );
process.exit( 1 );
}

const result = spawn.sync(
'node',
[
require.resolve( `../scripts/${ scriptName }-script` ),
...nodeArgs
],
{ stdio: 'inherit' }
);
if ( result.signal ) {
if ( result.signal === 'SIGKILL' ) {
console.log(
'The build failed because the process exited too early. ' +
'This probably means the system ran out of memory or someone called ' +
'`kill -9` on the process.'
);
} else if ( result.signal === 'SIGTERM' ) {
console.log(
'The build failed because the process exited too early. ' +
'Someone might have called `kill` or `killall`, or the system could ' +
'be shutting down.'
);
}
process.exit( 1 );
}
process.exit( result.status );
Loading

0 comments on commit 7ee6367

Please sign in to comment.