UNPKG

1.43 kBJavaScriptView Raw
1'use strict';
2
3const chai = require('chai');
4const execa = require('execa');
5const path = require('path');
6
7const busted = /v4|v6/.test(process.version) ? '--old-and-busted' : '';
8const cli = (args, opts) => {
9 const cliPath = path.join(cwd, 'cli');
10 const params = [cliPath].concat(args, busted);
11
12 return execa(process.execPath, params, opts);
13};
14const cwd = path.dirname(__dirname);
15const expect = chai.expect;
16const pkg = require(path.join(cwd, 'package.json'));
17
18describe('mocha-chrome binary', () => {
19
20 it('should report version', async () => {
21 const { stdout } = await cli(['--version'], {cwd});
22
23 expect(stdout).to.equal(pkg.version);
24 });
25
26 it('should run a successful test', async () => {
27 const { code } = await cli(['test/html/test.html'], {cwd});
28 expect(code).to.equal(0);
29 });
30
31 it('should run a failing test', (done) => {
32 cli(['test/html/fail.html'], {cwd}).catch(err => {
33 expect(err.code).to.equal(1);
34 expect(err.stdout).to.match(/1 failing/);
35 done();
36 });
37 });
38
39 it('should default to "spec" reporter', async () => {
40 const { code, stdout } = await cli(['test/html/test.html'], {cwd});
41 expect(stdout).to.match(/✓/);
42 });
43
44 it('should honor --spec parameter', async () => {
45 const { code, stdout } = await cli(['--reporter', 'tap', 'test/html/test.html'], {cwd});
46 expect(stdout).to.match(/ok/);
47 expect(stdout).not.to.match(/✓/);
48 });
49});