Skip to content

Commit

Permalink
Rename pattern to glob
Browse files Browse the repository at this point in the history
  • Loading branch information
yosuke-furukawa committed Jun 19, 2016
1 parent d56b4d8 commit 6f6552a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $ eater

![image](https://github.com/yosuke-furukawa/eater/raw/master/images/screenshot.png)

## eater `--dir` and `--ext`
## eater `--dir` and `--ext` and `--glob`

eater searches JavaScript files under `process.cwd()/test` dir by default. If you want to change the dir, use `--dir` option.

Expand All @@ -62,6 +62,12 @@ And if you changed test file extension, like `.jsx/.es6/.test.js`, you use `--ex
$ eater --ext jsx
```

eater can find test files using glob pattern match. you use `--glob` option.

```
$ eater --glob **/__test/**/*.js
```

### file

```
Expand Down
6 changes: 3 additions & 3 deletions bin/eater.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const opts = require('./opts')(argv, execArgv, process.cwd());

function showHelp() {
console.log(`
eater [--dir test directroy default 'test/'] [--ext test file extension default '.js'] [--pattern test file path pattern like 'test/**/*.js'] [--reporter fooreporter] [--procs max process number default cpu core num] [--require prerequire modules]
eater [--dir test directroy default 'test/'] [--ext test file extension default '.js'] [--glob find test files using glob pattern match like 'test/**/*.js'] [--reporter fooreporter] [--procs max process number default cpu core num] [--require prerequire modules]
eater --dir test/lib
eater --dir spec --ext .js
eater --dir test/lib --ext .test.js
eater --dir test/lib --ext .test.js --reporter SomeCustomReporter
eater --dir test/lib --ext .test.js --procs 10
eater --pattern **/__test__/**/*.js
eater --glob **/__test__/**/*.js
eater --require foo/bar
eater --eaterrc example/dir/.eaterrc
eater test/foo.js test/bar.js test/buz.js
Expand Down Expand Up @@ -47,7 +47,7 @@ const eater = new Eater({
reporter: new opts.Reporter(),
dir: opts.dir,
ext: opts.ext,
pattern: opts.pattern,
glob: opts.glob,
procs: opts.procs,
requires: requires,
targets: opts.targets,
Expand Down
4 changes: 2 additions & 2 deletions bin/opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const opts = (argv, execArgv, cwd) => {
var reporter = argv.reporter || eaterrc.reporter;
var dir = argv.dir || eaterrc.dir || 'test/';
var ext = argv.ext || eaterrc.ext || '.js';
var pattern = argv.pattern || eaterrc.pattern;
var glob = argv.glob || eaterrc.glob;
var procs = Number(argv.procs) || Number(eaterrc.procs) || 0;
var requires = argv.require || eaterrc.require || [];
var execRequires = execArgv.require || [];
Expand Down Expand Up @@ -50,7 +50,7 @@ const opts = (argv, execArgv, cwd) => {
return {
dir: dir,
ext: ext,
pattern: pattern,
glob: glob,
procs: procs,
help: help,
version: version,
Expand Down
4 changes: 2 additions & 2 deletions lib/eater.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Eater extends EventEmitter {
this.reporter = options.reporter;
this.dir = options.dir;
this.extension = options.ext || '.js';
this.pattern = options.pattern;
this.glob = options.glob;
this.procs = options.procs || DEFAULT_MAXPROCS;
this.targets = options.targets || [];
if (this.targets.length === 0) {
this.files = listupFiles(this.dir, this.extension, this.pattern);
this.files = listupFiles(this.dir, this.extension, this.glob);
} else {
this.files = this.targets;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/listupFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs');
const path = require('path');
const glob = require('glob');

module.exports = function listupFiles(dir, extention, pattern) {
module.exports = function listupFiles(dir, extention, globPattern) {
if (typeof dir !== 'string') {
throw new Error('dir should be string');
}
Expand All @@ -12,12 +12,12 @@ module.exports = function listupFiles(dir, extention, pattern) {
throw new Error('extension should be string');
}

if (pattern && !glob.hasMagic(pattern)) {
throw new Error('pattern should have magic glob chars like *, ?');
if (globPattern && !glob.hasMagic(globPattern)) {
throw new Error('glob pattern should have magic glob chars like *, ?');
}

if (pattern) {
return glob.sync(pattern)
if (globPattern) {
return glob.sync(globPattern);
}

let files = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const cp = require('child_process');
const assert = require('power-assert');

const result = cp.execSync(`node ${process.cwd()}/bin/eater.js --pattern **/__test__/**/*.js`).toString();
const result = cp.execSync(`node ${process.cwd()}/bin/eater.js --glob **/__test__/**/*.js`).toString();
assert(result.match(/test[\\/]fixture[\\/]__test__[\\/]b.js/));
2 changes: 1 addition & 1 deletion test/core/lib/listupFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ assert.throws(() => {

assert.throws(() => {
listupFiles('', '', 'test/foo/bar');
}, /pattern should have magic glob chars/ );
}, /glob pattern should have magic glob chars/ );

0 comments on commit 6f6552a

Please sign in to comment.