Skip to content

Commit 4e52131

Browse files
authored
Fix empty reports when path option to existing build is used (#293)
1 parent 053cbfa commit 4e52131

File tree

4 files changed

+156
-1
lines changed

4 files changed

+156
-1
lines changed

packages/ember-cli-code-coverage/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module.exports = {
9999
return;
100100
}
101101

102-
if (!this.fileLookup) {
102+
if (Object.keys(this.fileLookup || {}).length === 0) {
103103
this.included(this);
104104
}
105105
const config = {

test-packages/__snapshots__/my-app-test.js.snap

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,141 @@ Object {
566566
}
567567
`;
568568

569+
exports[`app coverage generation runs coverage when the path option is used 1`] = `
570+
Object {
571+
"app/app.js": Object {
572+
"branches": Object {
573+
"covered": 0,
574+
"pct": 100,
575+
"skipped": 0,
576+
"total": 0,
577+
},
578+
"functions": Object {
579+
"covered": 0,
580+
"pct": 100,
581+
"skipped": 0,
582+
"total": 0,
583+
},
584+
"lines": Object {
585+
"covered": 4,
586+
"pct": 100,
587+
"skipped": 0,
588+
"total": 4,
589+
},
590+
"statements": Object {
591+
"covered": 4,
592+
"pct": 100,
593+
"skipped": 0,
594+
"total": 4,
595+
},
596+
},
597+
"app/router.js": Object {
598+
"branches": Object {
599+
"covered": 0,
600+
"pct": 100,
601+
"skipped": 0,
602+
"total": 0,
603+
},
604+
"functions": Object {
605+
"covered": 0,
606+
"pct": 0,
607+
"skipped": 0,
608+
"total": 1,
609+
},
610+
"lines": Object {
611+
"covered": 1,
612+
"pct": 33.33,
613+
"skipped": 0,
614+
"total": 3,
615+
},
616+
"statements": Object {
617+
"covered": 1,
618+
"pct": 33.33,
619+
"skipped": 0,
620+
"total": 3,
621+
},
622+
},
623+
"app/utils/my-covered-util.js": Object {
624+
"branches": Object {
625+
"covered": 0,
626+
"pct": 100,
627+
"skipped": 0,
628+
"total": 0,
629+
},
630+
"functions": Object {
631+
"covered": 1,
632+
"pct": 100,
633+
"skipped": 0,
634+
"total": 1,
635+
},
636+
"lines": Object {
637+
"covered": 1,
638+
"pct": 100,
639+
"skipped": 0,
640+
"total": 1,
641+
},
642+
"statements": Object {
643+
"covered": 1,
644+
"pct": 100,
645+
"skipped": 0,
646+
"total": 1,
647+
},
648+
},
649+
"app/utils/my-uncovered-util.js": Object {
650+
"branches": Object {
651+
"covered": 0,
652+
"pct": 100,
653+
"skipped": 0,
654+
"total": 0,
655+
},
656+
"functions": Object {
657+
"covered": 0,
658+
"pct": 0,
659+
"skipped": 0,
660+
"total": 1,
661+
},
662+
"lines": Object {
663+
"covered": 0,
664+
"pct": 0,
665+
"skipped": 0,
666+
"total": 1,
667+
},
668+
"statements": Object {
669+
"covered": 0,
670+
"pct": 0,
671+
"skipped": 0,
672+
"total": 1,
673+
},
674+
},
675+
"total": Object {
676+
"branches": Object {
677+
"covered": 0,
678+
"pct": 100,
679+
"skipped": 0,
680+
"total": 0,
681+
},
682+
"functions": Object {
683+
"covered": 1,
684+
"pct": 33.33,
685+
"skipped": 0,
686+
"total": 3,
687+
},
688+
"lines": Object {
689+
"covered": 6,
690+
"pct": 66.67,
691+
"skipped": 0,
692+
"total": 9,
693+
},
694+
"statements": Object {
695+
"covered": 6,
696+
"pct": 66.67,
697+
"skipped": 0,
698+
"total": 9,
699+
},
700+
},
701+
}
702+
`;
703+
569704
exports[`app coverage generation uses nested coverageFolder and parallel configuration and run merge-coverage 1`] = `
570705
Object {
571706
"app/app.js": Object {

test-packages/index-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,19 @@ describe('index.js', function () {
119119
describe('when coverage is enabled', function () {
120120
beforeEach(function () {
121121
sandbox.stub(Index, '_isCoverageEnabled').returns(true);
122+
sandbox.stub(Index, 'included').value(sinon.spy());
122123
Index.testemMiddleware(app);
123124
});
124125

125126
it('adds POST endpoint to app', function () {
126127
expect(app.post.callCount).toEqual(1);
127128
});
129+
130+
describe('when the fileLookup is empty', function () {
131+
it('calls the included function', function () {
132+
expect(Index.included.callCount).toEqual(1);
133+
});
134+
});
128135
});
129136

130137
describe('when coverage is not enabled', function () {

test-packages/my-app-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ describe('app coverage generation', function () {
5656
expect(summary).toMatchSnapshot();
5757
});
5858

59+
it('runs coverage when the path option is used', async function () {
60+
dir(`${BASE_PATH}/coverage`).assertDoesNotExist();
61+
62+
let env = { COVERAGE: 'true' };
63+
await execa('ember', ['build', '--output-path=test-dist'], { cwd: BASE_PATH, env });
64+
await execa('ember', ['test', '--path=test-dist'], { cwd: BASE_PATH, env });
65+
file(`${BASE_PATH}/coverage/lcov-report/index.html`).assertIsNotEmpty();
66+
file(`${BASE_PATH}/coverage/index.html`).assertIsNotEmpty();
67+
68+
let summary = fs.readJSONSync(`${BASE_PATH}/coverage/coverage-summary.json`);
69+
expect(summary).toMatchSnapshot();
70+
});
71+
5972
it('merges coverage when tests are run in parallel', async function () {
6073
dir(`${BASE_PATH}/coverage`).assertDoesNotExist();
6174

0 commit comments

Comments
 (0)