Skip to content

Commit 3859487

Browse files
authored
Fix coverage report, ast compare test (#2236)
1 parent b79a123 commit 3859487

File tree

8 files changed

+689
-319
lines changed

8 files changed

+689
-319
lines changed

.github/workflows/nodejs.yml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,47 @@ name: Node CI
22

33
on: [push, pull_request]
44

5+
permissions:
6+
contents: read
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
512
jobs:
6-
build:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: actions/setup-node@v3
18+
with:
19+
cache: "yarn"
20+
- run: yarn install --frozen-lockfile
21+
- run: yarn lint
22+
23+
test:
724
runs-on: ${{ matrix.os }}
825

926
strategy:
1027
matrix:
1128
os: [ubuntu-latest, macos-latest, windows-latest]
1229
node-version: [14.x, 16.x, 18.x, 20.x]
1330

31+
env:
32+
ENABLE_COVERAGE: true
33+
AST_COMPARE: true
34+
1435
steps:
1536
- uses: actions/checkout@v3
1637
- name: Use Node.js ${{ matrix.node-version }}
1738
uses: actions/setup-node@v3
1839
with:
1940
node-version: ${{ matrix.node-version }}
20-
- name: yarn install, build, and test
21-
run: |
22-
yarn
23-
yarn lint
24-
yarn test
25-
yarn codecov
26-
env:
27-
CI: true
28-
AST_COMPARE: 1
41+
cache: "yarn"
42+
- run: yarn install --frozen-lockfile
43+
- run: yarn c8 yarn test:node
44+
- uses: codecov/codecov-action@v3
45+
with:
46+
fail_ci_if_error: true
47+
files: coverage/lcov.info
48+
- run: yarn test:standalone

build/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default {
4444
json(),
4545
babel({
4646
babelHelpers: "bundled",
47+
configFile: false,
4748
babelrc: false,
4849
plugins: [],
4950
compact: false,

jest.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
const ENABLE_COVERAGE = !!process.env.CI;
21
const RUN_STANDALONE_TESTS = Boolean(process.env.RUN_STANDALONE_TESTS);
2+
// Can't work on `jest-light-runner`
3+
// const ENABLE_COVERAGE =
4+
// !RUN_STANDALONE_TESTS && Boolean(process.env.ENABLE_COVERAGE);
35

46
export default {
5-
collectCoverage: ENABLE_COVERAGE,
7+
// collectCoverage: ENABLE_COVERAGE,
68
collectCoverageFrom: [
79
"<rootDir>/src/**/*.js",
810
"!<rootDir>/node_modules/",

package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@
3535
"@rollup/plugin-node-resolve": "^15.2.1",
3636
"@rollup/plugin-replace": "^5.0.2",
3737
"@rollup/plugin-terser": "^0.4.3",
38-
"codecov": "3.8.3",
38+
"c8": "^8.0.1",
3939
"cross-env": "^7.0.2",
4040
"eslint": "8.47.0",
4141
"eslint-config-prettier": "9.0.0",
4242
"eslint-plugin-import": "2.28.0",
4343
"eslint-plugin-jest": "27.2.3",
4444
"eslint-plugin-prettier": "5.0.0",
4545
"eslint-plugin-prettier-doc": "^1.1.0",
46-
"jest": "29.6.2",
47-
"jest-environment-jsdom": "29.6.2",
48-
"jest-light-runner": "^0.5.0",
46+
"jest": "29.6.4",
47+
"jest-environment-jsdom": "29.6.4",
48+
"jest-light-runner": "^0.5.1",
4949
"jest-snapshot-serializer-raw": "^1.1.0",
5050
"prettier": "^3.0.1",
5151
"rollup": "^3.28.1",
@@ -68,5 +68,15 @@
6868
"prettier": "prettier --plugin=src/index.js --parser=php",
6969
"build": "rollup --config build/rollup.config.js",
7070
"debug": "node --inspect-brk node_modules/.bin/jest --runInBand"
71+
},
72+
"c8": {
73+
"reporter": [
74+
"lcov",
75+
"text"
76+
],
77+
"all": true,
78+
"include": [
79+
"src/**"
80+
]
7181
}
7282
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const printers = {
135135
case "commentline": {
136136
return comment.value.trimRight();
137137
}
138-
/* istanbul ignore next */
138+
/* c8 ignore next 2 */
139139
default:
140140
throw new Error(`Not a comment: ${JSON.stringify(comment)}`);
141141
}

src/printer.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,9 @@ function printLookupNodes(path, options, print) {
826826
return printStaticLookup(path, options, print);
827827
case "offsetlookup":
828828
return printOffsetLookup(path, options, print);
829-
/* istanbul ignore next */
829+
/* c8 ignore next 2 */
830830
default:
831-
return `Have not implemented lookup kind ${node.kind} yet.`;
831+
throw new Error(`Have not implemented lookup kind ${node.kind} yet.`);
832832
}
833833
}
834834

@@ -846,8 +846,8 @@ function getEncapsedQuotes(node, { opening = true } = {}) {
846846
return quotes[node.type];
847847
}
848848

849-
/* istanbul ignore next */
850-
return `Unimplemented encapsed type ${node.type}`;
849+
/* c8 ignore next */
850+
throw new Error(`Unimplemented encapsed type ${node.type}`);
851851
}
852852

853853
function printArrayItems(path, options, print) {
@@ -2750,9 +2750,9 @@ function printNode(path, options, print) {
27502750
: "",
27512751
];
27522752
}
2753-
// istanbul ignore next
2753+
/* c8 ignore next 2 */
27542754
default:
2755-
return `Have not implemented kind ${node.type} yet.`;
2755+
throw new Error(`Have not implemented kind ${node.type} yet.`);
27562756
}
27572757
case "inline":
27582758
return join(
@@ -2881,9 +2881,9 @@ function printNode(path, options, print) {
28812881
case "variadicplaceholder":
28822882
return "...";
28832883

2884+
/* c8 ignore next 3 */
28842885
case "error":
28852886
default:
2886-
// istanbul ignore next
28872887
throw new Error(`Have not implemented kind '${node.kind}' yet.`);
28882888
}
28892889
}

tests_config/run_spec.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,27 +105,27 @@ global.run_spec = (importMeta, parsers, options) => {
105105

106106
// this will only work for php tests (since we're in the php repo)
107107
if (AST_COMPARE && parsers[0] === "php") {
108-
test(`${filename} parse`, () => {
109-
const parseOptions = Object.assign({}, mainOptions);
110-
delete parseOptions.cursorOffset;
111-
112-
const originalAst = parse(input, parseOptions);
113-
let formattedAst;
114-
115-
expect(() => {
116-
formattedAst = parse(
117-
output.replace(CURSOR_PLACEHOLDER, ""),
118-
parseOptions
119-
);
120-
}).not.toThrow();
121-
expect(originalAst).toEqual(formattedAst);
108+
test(`${filename} parse`, async () => {
109+
const parseOptions = { ...mainOptions, cursorOffset: undefined };
110+
111+
const originalAst = await parse(input, parseOptions);
112+
const formattedAst = await parse(
113+
output.replace(CURSOR_PLACEHOLDER, ""),
114+
parseOptions
115+
);
116+
117+
expect(originalAst).toBeDefined();
118+
expect(formattedAst).toEqual(originalAst);
122119
});
123120
}
124121
});
125122
};
126123

127-
function parse(source, options) {
128-
return prettier.__debug.parse(source, options, /* massage */ true).ast;
124+
async function parse(source, options) {
125+
const { ast } = await prettier.__debug.parse(source, options, {
126+
massage: true,
127+
});
128+
return ast;
129129
}
130130

131131
async function format(source, filename, options) {

0 commit comments

Comments
 (0)