Skip to content

Commit

Permalink
Fix empty reports when path option to existing build is used (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinborst95 authored Oct 4, 2020
1 parent 053cbfa commit 4e52131
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-cli-code-coverage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports = {
return;
}

if (!this.fileLookup) {
if (Object.keys(this.fileLookup || {}).length === 0) {
this.included(this);
}
const config = {
Expand Down
135 changes: 135 additions & 0 deletions test-packages/__snapshots__/my-app-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,141 @@ Object {
}
`;

exports[`app coverage generation runs coverage when the path option is used 1`] = `
Object {
"app/app.js": Object {
"branches": Object {
"covered": 0,
"pct": 100,
"skipped": 0,
"total": 0,
},
"functions": Object {
"covered": 0,
"pct": 100,
"skipped": 0,
"total": 0,
},
"lines": Object {
"covered": 4,
"pct": 100,
"skipped": 0,
"total": 4,
},
"statements": Object {
"covered": 4,
"pct": 100,
"skipped": 0,
"total": 4,
},
},
"app/router.js": Object {
"branches": Object {
"covered": 0,
"pct": 100,
"skipped": 0,
"total": 0,
},
"functions": Object {
"covered": 0,
"pct": 0,
"skipped": 0,
"total": 1,
},
"lines": Object {
"covered": 1,
"pct": 33.33,
"skipped": 0,
"total": 3,
},
"statements": Object {
"covered": 1,
"pct": 33.33,
"skipped": 0,
"total": 3,
},
},
"app/utils/my-covered-util.js": Object {
"branches": Object {
"covered": 0,
"pct": 100,
"skipped": 0,
"total": 0,
},
"functions": Object {
"covered": 1,
"pct": 100,
"skipped": 0,
"total": 1,
},
"lines": Object {
"covered": 1,
"pct": 100,
"skipped": 0,
"total": 1,
},
"statements": Object {
"covered": 1,
"pct": 100,
"skipped": 0,
"total": 1,
},
},
"app/utils/my-uncovered-util.js": Object {
"branches": Object {
"covered": 0,
"pct": 100,
"skipped": 0,
"total": 0,
},
"functions": Object {
"covered": 0,
"pct": 0,
"skipped": 0,
"total": 1,
},
"lines": Object {
"covered": 0,
"pct": 0,
"skipped": 0,
"total": 1,
},
"statements": Object {
"covered": 0,
"pct": 0,
"skipped": 0,
"total": 1,
},
},
"total": Object {
"branches": Object {
"covered": 0,
"pct": 100,
"skipped": 0,
"total": 0,
},
"functions": Object {
"covered": 1,
"pct": 33.33,
"skipped": 0,
"total": 3,
},
"lines": Object {
"covered": 6,
"pct": 66.67,
"skipped": 0,
"total": 9,
},
"statements": Object {
"covered": 6,
"pct": 66.67,
"skipped": 0,
"total": 9,
},
},
}
`;

exports[`app coverage generation uses nested coverageFolder and parallel configuration and run merge-coverage 1`] = `
Object {
"app/app.js": Object {
Expand Down
7 changes: 7 additions & 0 deletions test-packages/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,19 @@ describe('index.js', function () {
describe('when coverage is enabled', function () {
beforeEach(function () {
sandbox.stub(Index, '_isCoverageEnabled').returns(true);
sandbox.stub(Index, 'included').value(sinon.spy());
Index.testemMiddleware(app);
});

it('adds POST endpoint to app', function () {
expect(app.post.callCount).toEqual(1);
});

describe('when the fileLookup is empty', function () {
it('calls the included function', function () {
expect(Index.included.callCount).toEqual(1);
});
});
});

describe('when coverage is not enabled', function () {
Expand Down
13 changes: 13 additions & 0 deletions test-packages/my-app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ describe('app coverage generation', function () {
expect(summary).toMatchSnapshot();
});

it('runs coverage when the path option is used', async function () {
dir(`${BASE_PATH}/coverage`).assertDoesNotExist();

let env = { COVERAGE: 'true' };
await execa('ember', ['build', '--output-path=test-dist'], { cwd: BASE_PATH, env });
await execa('ember', ['test', '--path=test-dist'], { cwd: BASE_PATH, env });
file(`${BASE_PATH}/coverage/lcov-report/index.html`).assertIsNotEmpty();
file(`${BASE_PATH}/coverage/index.html`).assertIsNotEmpty();

let summary = fs.readJSONSync(`${BASE_PATH}/coverage/coverage-summary.json`);
expect(summary).toMatchSnapshot();
});

it('merges coverage when tests are run in parallel', async function () {
dir(`${BASE_PATH}/coverage`).assertDoesNotExist();

Expand Down

0 comments on commit 4e52131

Please sign in to comment.