|
| 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 | +}); |
0 commit comments