-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathapp-coverage-test.js
113 lines (100 loc) · 4.3 KB
/
app-coverage-test.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'use strict';
var fs = require('fs-extra');
var RSVP = require('rsvp');
var rimraf = RSVP.denodeify(require('rimraf'));
var chai = require('chai');
var expect = chai.expect;
var chaiFiles = require('chai-files');
var dir = chaiFiles.dir;
var file = chaiFiles.file;
var path = require('path');
const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
chai.use(chaiFiles);
let app;
describe('app coverage generation', function() {
this.timeout(10000000);
beforeEach(function() {
app = new AddonTestApp();
return app.create('my-app', {
emberVersion: '2.16.0'
}).then(() => {
app.editPackageJSON(pkg => {
pkg.devDependencies['ember-exam'] = '0.7.0';
// Temporarily remove the addon before install to work around https://github.com/tomdale/ember-cli-addon-tests/issues/176
delete pkg.devDependencies['ember-cli-code-coverage'];
});
return app.run('npm', 'install').then(() => {
app.editPackageJSON(pkg => {
pkg.devDependencies['ember-cli-code-coverage'] = '*';
});
let addonPath = path.join(app.path, 'node_modules', 'ember-cli-code-coverage');
fs.removeSync(addonPath);
fs.ensureSymlinkSync(process.cwd(), addonPath);
return rimraf(`${app.path}/coverage*`);
});
});
});
afterEach(function() {
return RSVP.all([
rimraf(`${app.path}/config/coverage.js`)
]);
});
it('runs coverage when env var is set', function() {
expect(dir(`${app.path}/coverage`)).to.not.exist;
process.env.COVERAGE = true;
return app.run('ember', 'test').then(function() {
expect(file(`${app.path}/coverage/lcov-report/index.html`)).to.not.be.empty;
expect(file(`${app.path}/coverage/index.html`)).to.not.be.empty;
var summary = fs.readJSONSync(`${app.path}/coverage/coverage-summary.json`);
expect(summary.total.lines.pct).to.equal(83.33);
});
});
it('does not run coverage when env var is NOT set', function() {
expect(dir(`${app.path}/coverage`)).to.not.exist;
process.env.COVERAGE = false;
return app.run('ember', 'test').then(function() {
expect(dir(`${app.path}/coverage`)).to.not.exist;
});
});
it('excludes files when the configuration is set', function() {
fs.copySync('tests/dummy/config/coverage-excludes.js', `${app.path}/config/coverage.js`);
process.env.COVERAGE = true;
return app.run('ember', 'test').then(function() {
expect(file(`${app.path}/coverage/lcov-report/index.html`)).to.not.be.empty;
expect(file(`${app.path}/coverage/index.html`)).to.not.be.empty;
var summary = fs.readJSONSync(`${app.path}/coverage/coverage-summary.json`);
expect(summary.total.lines.pct).to.equal(100);
});
});
it('merges coverage when tests are run in parallel', function() {
expect(dir(`${app.path}/coverage`)).to.not.exist;
process.env.COVERAGE = true;
return app.run('ember', 'exam', '--split=2', '--parallel=true').then(function() {
expect(file(`${app.path}/coverage/lcov-report/index.html`)).to.not.be.empty;
expect(file(`${app.path}/coverage/index.html`)).to.not.be.empty;
var summary = fs.readJSONSync(`${app.path}/coverage/coverage-summary.json`);
expect(summary.total.lines.pct).to.equal(83.33);
});
});
it('uses nested coverageFolder', function() {
var coverageFolder = `${app.path}/coverage/abc/easy-as/123`;
expect(dir(coverageFolder)).to.not.exist;
fs.copySync('tests/dummy/config/coverage-nested-folder.js', `${app.path}/config/coverage.js`);
process.env.COVERAGE = true;
return app.run('ember', 'exam', '--split=2', '--parallel=true').then(function() {
expect(file(`${coverageFolder}/lcov-report/index.html`)).to.not.be.empty;
expect(file(`${coverageFolder}/index.html`)).to.not.be.empty;
var summary = fs.readJSONSync(`${coverageFolder}/coverage-summary.json`);
expect(summary.total.lines.pct).to.equal(83.33);
});
});
it('runs coverage when a module has an import error', function() {
expect(dir(`${app.path}/coverage`)).to.not.exist;
fs.copySync('test/helpers/error-module.js', `${app.path}/app/error-module.js`);
process.env.COVERAGE = true;
return app.run('ember', 'test').then(function() {
expect(dir(`${app.path}/coverage`)).to.exist;
return rimraf(`${app.path}/app/error-module.js`);
});
});
});