|
1 |
| -const process = require('process'); |
2 |
| -const cp = require('child_process'); |
3 |
| -const path = require('path'); |
4 |
| -const { fail } = require('assert'); |
| 1 | +const process = require("process"); |
| 2 | +const cp = require("child_process"); |
| 3 | +const path = require("path"); |
| 4 | +const { fail } = require("assert"); |
5 | 5 |
|
6 | 6 | const getErrorOutput = (error) => {
|
7 | 7 | const output = Array(...error.output)
|
8 | 8 | .filter((line) => !!line)
|
9 |
| - .map((line) => line.toString().replace(/%0A/g, '\n')) |
| 9 | + .map((line) => line.toString().replace(/%0A/g, "\n")) |
10 | 10 | .filter((line) => line.trim().length > 0)
|
11 |
| - .join('\n'); |
| 11 | + .join("\n"); |
12 | 12 | return output;
|
13 | 13 | };
|
14 | 14 |
|
15 |
| -test('invalid LCOV format throws an error', () => { |
16 |
| - const lcovPath = './fixtures/lcov.error.info'; |
17 |
| - process.env['INPUT_PATH'] = lcovPath; |
18 |
| - const ip = path.join(__dirname, 'index.js'); |
| 15 | +test("invalid LCOV format throws an error", () => { |
| 16 | + const lcovPath = "./fixtures/lcov.error.info"; |
| 17 | + process.env["INPUT_PATH"] = lcovPath; |
| 18 | + const ip = path.join(__dirname, "index.js"); |
19 | 19 | try {
|
20 | 20 | cp.execSync(`node ${ip}`, { env: process.env }).toString();
|
21 |
| - fail('this code should fail'); |
| 21 | + fail("this code should fail"); |
22 | 22 | } catch (err) {
|
23 | 23 | expect(err).toBeDefined();
|
24 | 24 | }
|
25 | 25 | });
|
26 | 26 |
|
27 |
| -test('completes when the coverage is 100 and min_coverage is not provided', () => { |
28 |
| - const lcovPath = './fixtures/lcov.100.info'; |
29 |
| - process.env['INPUT_PATH'] = lcovPath; |
30 |
| - const ip = path.join(__dirname, 'index.js'); |
| 27 | +test("completes when the coverage is 100 and min_coverage is not provided", () => { |
| 28 | + const lcovPath = "./fixtures/lcov.100.info"; |
| 29 | + process.env["INPUT_PATH"] = lcovPath; |
| 30 | + const ip = path.join(__dirname, "index.js"); |
31 | 31 | cp.execSync(`node ${ip}`, { env: process.env }).toString();
|
32 | 32 | });
|
33 | 33 |
|
34 |
| -test('completes when the coverage is higher than the threshold after excluding files', () => { |
35 |
| - const lcovPath = './fixtures/lcov.100.info'; |
36 |
| - const exclude = '**/*_observer.dart'; |
37 |
| - process.env['INPUT_PATH'] = lcovPath; |
38 |
| - process.env['INPUT_EXCLUDE'] = exclude; |
39 |
| - const ip = path.join(__dirname, 'index.js'); |
| 34 | +test("completes when the coverage is higher than the threshold after excluding files", () => { |
| 35 | + const lcovPath = "./fixtures/lcov.100.info"; |
| 36 | + const exclude = "**/*_observer.dart"; |
| 37 | + process.env["INPUT_PATH"] = lcovPath; |
| 38 | + process.env["INPUT_EXCLUDE"] = exclude; |
| 39 | + const ip = path.join(__dirname, "index.js"); |
40 | 40 | cp.execSync(`node ${ip}`, { env: process.env }).toString();
|
41 | 41 | });
|
42 | 42 |
|
43 |
| -test('fails when the coverage is not 100 and min_coverage is not provided', () => { |
44 |
| - const lcovPath = './fixtures/lcov.95.info'; |
45 |
| - process.env['INPUT_PATH'] = lcovPath; |
46 |
| - const ip = path.join(__dirname, 'index.js'); |
| 43 | +test("fails when the coverage is not 100 and min_coverage is not provided", () => { |
| 44 | + const lcovPath = "./fixtures/lcov.95.info"; |
| 45 | + process.env["INPUT_PATH"] = lcovPath; |
| 46 | + const ip = path.join(__dirname, "index.js"); |
47 | 47 | try {
|
48 | 48 | cp.execSync(`node ${ip}`, { env: process.env }).toString();
|
49 |
| - fail('this code should fail'); |
| 49 | + fail("this code should fail"); |
50 | 50 | } catch (err) {
|
51 | 51 | expect(err).toBeDefined();
|
52 | 52 | }
|
53 | 53 | });
|
54 | 54 |
|
55 |
| -test('fails when the coverage is below the min_coverage, even if we exclude files', () => { |
56 |
| - const lcovPath = './fixtures/lcov.100.info'; |
57 |
| - const exclude = '**/does_not_exist.dart'; |
58 |
| - process.env['INPUT_PATH'] = lcovPath; |
59 |
| - process.env['INPUT_EXCLUDE'] = exclude; |
60 |
| - const ip = path.join(__dirname, 'index.js'); |
| 55 | +test("fails when the coverage is below the min_coverage, even if we exclude files", () => { |
| 56 | + const lcovPath = "./fixtures/lcov.100.info"; |
| 57 | + const exclude = "**/does_not_exist.dart"; |
| 58 | + process.env["INPUT_PATH"] = lcovPath; |
| 59 | + process.env["INPUT_EXCLUDE"] = exclude; |
| 60 | + const ip = path.join(__dirname, "index.js"); |
61 | 61 | try {
|
62 | 62 | cp.execSync(`node ${ip}`, { env: process.env }).toString();
|
63 |
| - fail('this code should fail'); |
| 63 | + fail("this code should fail"); |
64 | 64 | } catch (err) {
|
65 | 65 | expect(err).toBeDefined();
|
66 | 66 | }
|
67 | 67 | });
|
68 | 68 |
|
69 |
| -test('completes when the coverage is above the given min_threshold', () => { |
70 |
| - const lcovPath = './fixtures/lcov.95.info'; |
| 69 | +test("completes when the coverage is above the given min_threshold", () => { |
| 70 | + const lcovPath = "./fixtures/lcov.95.info"; |
71 | 71 | const minCoverage = 80;
|
72 |
| - process.env['INPUT_PATH'] = lcovPath; |
73 |
| - process.env['INPUT_MIN_COVERAGE'] = minCoverage; |
74 |
| - const ip = path.join(__dirname, 'index.js'); |
| 72 | + process.env["INPUT_PATH"] = lcovPath; |
| 73 | + process.env["INPUT_MIN_COVERAGE"] = minCoverage; |
| 74 | + const ip = path.join(__dirname, "index.js"); |
75 | 75 | cp.execSync(`node ${ip}`, { env: process.env }).toString();
|
76 | 76 | });
|
77 | 77 |
|
78 |
| -test('fails when the coverage is below the given min_threshold', () => { |
79 |
| - const lcovPath = './fixtures/lcov.95.info'; |
| 78 | +test("fails when the coverage is below the given min_threshold", () => { |
| 79 | + const lcovPath = "./fixtures/lcov.95.info"; |
80 | 80 | const minCoverage = 98;
|
81 |
| - process.env['INPUT_PATH'] = lcovPath; |
82 |
| - process.env['INPUT_MIN_COVERAGE'] = minCoverage; |
83 |
| - const ip = path.join(__dirname, 'index.js'); |
| 81 | + process.env["INPUT_PATH"] = lcovPath; |
| 82 | + process.env["INPUT_MIN_COVERAGE"] = minCoverage; |
| 83 | + const ip = path.join(__dirname, "index.js"); |
84 | 84 | try {
|
85 | 85 | cp.execSync(`node ${ip}`, { env: process.env }).toString();
|
86 |
| - fail('this code should fail'); |
| 86 | + fail("this code should fail"); |
87 | 87 | } catch (err) {
|
88 | 88 | expect(err).toBeDefined();
|
89 | 89 | }
|
90 | 90 | });
|
91 | 91 |
|
92 |
| -test('shows lines that are missing coverage when failure occurs', () => { |
93 |
| - const lcovPath = './fixtures/lcov.95.info'; |
| 92 | +test("shows lines that are missing coverage when failure occurs", () => { |
| 93 | + const lcovPath = "./fixtures/lcov.95.info"; |
94 | 94 | const minCoverage = 100;
|
95 |
| - process.env['INPUT_PATH'] = lcovPath; |
96 |
| - process.env['INPUT_MIN_COVERAGE'] = minCoverage; |
97 |
| - const ip = path.join(__dirname, 'index.js'); |
| 95 | + process.env["INPUT_PATH"] = lcovPath; |
| 96 | + process.env["INPUT_MIN_COVERAGE"] = minCoverage; |
| 97 | + const ip = path.join(__dirname, "index.js"); |
98 | 98 | try {
|
99 | 99 | cp.execSync(`node ${ip}`, { env: process.env }).toString();
|
100 |
| - fail('this code should fail'); |
| 100 | + fail("this code should fail"); |
101 | 101 | } catch (err) {
|
102 | 102 | const output = getErrorOutput(err);
|
103 |
| - expect(output).toContain('Lines not covered'); |
| 103 | + expect(output).toContain("Lines not covered"); |
104 | 104 | expect(output).toContain(
|
105 |
| - '/Users/felix/Development/github.com/felangel/bloc/packages/bloc/lib/src/bloc_observer.dart: 20, 27, 36, 43, 51' |
| 105 | + "/Users/felix/Development/github.com/felangel/bloc/packages/bloc/lib/src/bloc_observer.dart: 20, 27, 36, 43, 51" |
106 | 106 | );
|
107 | 107 | }
|
108 | 108 | });
|
0 commit comments