Skip to content

Commit 56fefb9

Browse files
committed
build: test code must run in older node.js
We must disable eslint rules that require new javascript features in test files, because test files are not currently compiled by `tsc`. TODO: doesn't look like babel is configured to run on the "neovim" package. I tried this: M packages/neovim/package.json @@ -72,7 +72,7 @@ "test-staged": "npm test --bail --no-cache --findRelatedTests", "test-missing-apis": "npm run build && node scripts/findMissingApi", "precommit": "lint-staged", - "build": "tsc --pretty", + "build": "tsc --pretty && babel lib --out-dir lib", "dev": "npm run build --watch true" }, "jest": { M packages/neovim/src/utils/getNvimFromEnv.ts @@ -149,6 +149,8 @@ export function getNvimFromEnv( const paths = process.env.PATH.split(delimiter); const pathLength = paths.length; const matches = new Array<NvimVersion>(); + const foo = matches.at(-1); + console.log(foo); // test const unmatchedVersions = new Array<NvimVersion>(); const errors = new Array<GetNvimFromEnvError>(); for (let i = 0; i !== pathLength; i = i + 1) { Babel didn't translate the file to the desired node.js 8 compatible syntax (it should replace `matches.at()` with `matches[…]`).
1 parent 1d61403 commit 56fefb9

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.eslintrc.js

+16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ module.exports = {
1616
es2024: true,
1717
},
1818

19+
overrides: [
20+
{
21+
files: ['*.test.ts'],
22+
// excludedFiles: ['bin/*.ts', 'lib/*.ts'],
23+
rules: {
24+
// This rule requires es2022(?) but the CI node14 job runs the tests
25+
// in node14, but the test code is not compiled/polyfilled... so the
26+
// test code needs to be compatible with node14.
27+
// TODO: can the back-compat CI jobs for older node.js versions run
28+
// `jest` against the compiled .js results (would require compiling
29+
// the test files as well)?
30+
'unicorn/prefer-at': 'off',
31+
}
32+
}
33+
],
34+
1935
rules: {
2036
curly: 'error', // Enforce braces on "if"/"for"/etc.
2137
// Avoid accidental use of "==" instead of "===".

packages/neovim/src/api/Tabpage.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('Tabpage API', () => {
6565
const tabpages = await nvim.tabpages;
6666
expect(tabpages.length).toBe(2);
6767

68-
nvim.tabpage = tabpages.at(-1);
68+
nvim.tabpage = tabpages[tabpages.length - 1];
6969

7070
const newTabPage = await nvim.tabpage;
7171
expect(await newTabPage.number).toBe(2);
@@ -139,7 +139,7 @@ describe('Tabpage API', () => {
139139
// TODO
140140
expect((await nvim.tabpages).length).toBe(2);
141141

142-
nvim.tabpage = tabpages.at(-1);
142+
nvim.tabpage = tabpages[tabpages.length - 1];
143143

144144
expect(await nvim.tabpage.number).toBe(2);
145145
});

0 commit comments

Comments
 (0)