-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scripts: New scripts package containing test command (#62)
* Scripts: initial commit with scripts package containing test command * Publish - @wordpress/[email protected] * Scripts: Minor changes before publishing to npm
- Loading branch information
Showing
9 changed files
with
5,490 additions
and
3,403 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
Oops, something went wrong.