Skip to content

Commit fc44444

Browse files
committed
Add tests for the test packages
1 parent 690fa09 commit fc44444

File tree

7 files changed

+2642
-52
lines changed

7 files changed

+2642
-52
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ jobs:
2525
- run: yarn lint:js
2626
working-directory: packages/ember-cli-code-coverage
2727

28+
- run: yarn test
29+
2830
- run: yarn node-test
2931
working-directory: packages/ember-cli-code-coverage

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,15 @@
33
"workspaces": [
44
"packages/*",
55
"test-packages/*"
6+
],
7+
"scripts": {
8+
"test": "mocha test-packages/*-test.js"
9+
},
10+
"devDependencies": {
11+
"chai": "^4.2.0",
12+
"chai-files": "^1.4.0",
13+
"execa": "^4.0.3",
14+
"mocha": "^5.2.0",
15+
"rimraf": "^2.6.2"
16+
}
617
}

test-packages/in-repo-addon-test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict';
2+
3+
const fs = require('fs-extra');
4+
const util = require('util');
5+
const rimraf = util.promisify(require('rimraf'));
6+
const chai = require('chai');
7+
const expect = chai.expect;
8+
const chaiFiles = require('chai-files');
9+
const dir = chaiFiles.dir;
10+
const file = chaiFiles.file;
11+
const path = require('path');
12+
const execa = require('execa');
13+
14+
chai.use(chaiFiles);
15+
16+
const BASE_PATH = path.join(__dirname, 'my-app-with-in-repo-addon');
17+
18+
describe('in-repo addon coverage generation', function () {
19+
this.timeout(10000000);
20+
21+
beforeEach(async function () {
22+
await rimraf(`${BASE_PATH}/coverage*`);
23+
await execa('git', ['clean', '-f', 'my-app-with-in-repo-addon'], { cwd: __dirname });
24+
await execa('git', ['restore', 'my-app-with-in-repo-addon'], { cwd: __dirname });
25+
});
26+
27+
afterEach(async function () {
28+
await rimraf(`${BASE_PATH}/coverage*`);
29+
await execa('git', ['clean', '-f', 'my-app-with-in-repo-addon'], { cwd: __dirname });
30+
await execa('git', ['restore', 'my-app-with-in-repo-addon'], { cwd: __dirname });
31+
});
32+
33+
it('runs coverage on in-repo addon', async function () {
34+
expect(dir(`${BASE_PATH}/coverage`)).to.not.exist;
35+
36+
let env = { COVERAGE: 'true' };
37+
await execa('ember', ['test'], { cwd: BASE_PATH, env });
38+
expect(file(`${BASE_PATH}/coverage/lcov-report/index.html`)).to.not.be.empty;
39+
expect(file(`${BASE_PATH}/coverage/index.html`)).to.not.be.empty;
40+
41+
const summary = fs.readJSONSync(`${BASE_PATH}/coverage/coverage-summary.json`);
42+
expect(summary.total.lines.pct).to.equal(46.67);
43+
expect(summary['app/utils/my-covered-util-app.js'].lines.total).to.equal(1);
44+
45+
// Check that lib/my-in-repo-addon/utils/my-covered-utill is 1 line and that 1 line is covered
46+
expect(summary['lib/my-in-repo-addon/addon/utils/my-covered-util.js'].lines.total).to.equal(1);
47+
expect(summary['lib/my-in-repo-addon/addon/utils/my-covered-util.js'].lines.covered).to.equal(
48+
1
49+
);
50+
51+
// Check that lib/my-in-repo-addon/utils/my-uncovered-utill is 1 line and that 0 lines are covered
52+
expect(summary['lib/my-in-repo-addon/addon/utils/my-uncovered-util.js'].lines.total).to.equal(
53+
1
54+
);
55+
expect(summary['lib/my-in-repo-addon/addon/utils/my-uncovered-util.js'].lines.covered).to.equal(
56+
0
57+
);
58+
59+
// Check that lib/my-in-repo-addon/addon-test-support/uncovered-test-support is 4 lines and that 0 lines are covered
60+
expect(
61+
summary['lib/my-in-repo-addon/addon-test-support/uncovered-test-support.js'].lines.total
62+
).to.equal(4);
63+
expect(
64+
summary['lib/my-in-repo-addon/addon-test-support/uncovered-test-support.js'].lines.covered
65+
).to.equal(0);
66+
});
67+
});

test-packages/in-repo-engine-test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use strict';
2+
3+
const fs = require('fs-extra');
4+
const util = require('util');
5+
const rimraf = util.promisify(require('rimraf'));
6+
const chai = require('chai');
7+
const expect = chai.expect;
8+
const chaiFiles = require('chai-files');
9+
const dir = chaiFiles.dir;
10+
const file = chaiFiles.file;
11+
const path = require('path');
12+
const execa = require('execa');
13+
14+
chai.use(chaiFiles);
15+
16+
const BASE_PATH = path.join(__dirname, 'my-app-with-in-repo-engine');
17+
18+
describe('in-repo engine coverage generation', function () {
19+
this.timeout(10000000);
20+
21+
beforeEach(async function () {
22+
await rimraf(`${BASE_PATH}/coverage*`);
23+
await execa('git', ['clean', '-f', 'my-app-with-in-repo-engine'], { cwd: __dirname });
24+
await execa('git', ['restore', 'my-app-with-in-repo-engine'], { cwd: __dirname });
25+
});
26+
27+
afterEach(async function () {
28+
await rimraf(`${BASE_PATH}/coverage*`);
29+
await execa('git', ['clean', '-f', 'my-app-with-in-repo-engine'], { cwd: __dirname });
30+
await execa('git', ['restore', 'my-app-with-in-repo-engine'], { cwd: __dirname });
31+
});
32+
33+
it('runs coverage on in-repo engine', async function () {
34+
expect(dir(`${BASE_PATH}/coverage`)).to.not.exist;
35+
36+
let env = { COVERAGE: 'true' };
37+
await execa('ember', ['test'], { cwd: BASE_PATH, env });
38+
expect(file(`${BASE_PATH}/coverage/lcov-report/index.html`)).to.not.be.empty;
39+
expect(file(`${BASE_PATH}/coverage/index.html`)).to.not.be.empty;
40+
41+
const summary = fs.readJSONSync(`${BASE_PATH}/coverage/coverage-summary.json`);
42+
expect(summary.total.lines.pct).to.equal(66.67);
43+
expect(summary['app/utils/my-covered-util-app.js'].lines.total).to.equal(1);
44+
45+
// Check that lib/my-in-repo-engine/utils/my-covered-utill is 1 line and that 1 line is covered
46+
expect(summary['lib/my-in-repo-engine/addon/utils/my-covered-util.js'].lines.total).to.equal(1);
47+
expect(summary['lib/my-in-repo-engine/addon/utils/my-covered-util.js'].lines.covered).to.equal(
48+
1
49+
);
50+
51+
// Check that lib/my-in-repo-engine/utils/my-uncovered-utill is 1 line and that 0 lines are covered
52+
expect(summary['lib/my-in-repo-engine/addon/utils/my-uncovered-util.js'].lines.total).to.equal(
53+
1
54+
);
55+
expect(
56+
summary['lib/my-in-repo-engine/addon/utils/my-uncovered-util.js'].lines.covered
57+
).to.equal(0);
58+
});
59+
});

0 commit comments

Comments
 (0)