-
Notifications
You must be signed in to change notification settings - Fork 754
/
bs.js
35 lines (31 loc) · 1.33 KB
/
bs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const cypress = require('cypress');
const exec = require('child_process');
const assert = require('assert');
const {join} = require('path');
const {Observable} = require('rxjs/Observable');
module.exports = function(opts, ctx) {
assert.ok(typeof opts.config === 'string', '`opts.config` should be a string');
assert.ok(typeof opts.spec === 'string', '`opts.spec` should be a string');
assert.ok((opts.action === 'run' || opts.action === 'open'), '`action` should be either run or open');
const json = require(join(ctx.config.cwd, opts.config));
return Observable.create(obs => {
const bs = require('../../packages/browser-sync').create();
const instance = bs.init(json, function(err, bs) {
if (err) {
return obs.error(err);
}
return cypress[opts.action]({
spec: opts.spec,
env: `BS_URL=${bs.options.getIn(['urls', 'local'])},BS_UI_URL=${bs.options.getIn(['urls', 'ui'])}`
})
.then((results) => {
// stop your server when it's complete
if (results.failures > 0) {
return obs.error(new Error('Errors occurred'));
}
instance.cleanup();
obs.complete();
})
});
});
};