From 56fefb9195cfe4e3e7a5c9a5d073eb18c4074992 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 3 Feb 2024 02:43:41 +0100 Subject: [PATCH] build: test code must run in older node.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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(); + const foo = matches.at(-1); + console.log(foo); // test const unmatchedVersions = new Array(); const errors = new Array(); 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[…]`). --- .eslintrc.js | 16 ++++++++++++++++ packages/neovim/src/api/Tabpage.test.ts | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 0ea7d0e8..18a3a6d6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -16,6 +16,22 @@ module.exports = { es2024: true, }, + overrides: [ + { + files: ['*.test.ts'], + // excludedFiles: ['bin/*.ts', 'lib/*.ts'], + rules: { + // This rule requires es2022(?) but the CI node14 job runs the tests + // in node14, but the test code is not compiled/polyfilled... so the + // test code needs to be compatible with node14. + // TODO: can the back-compat CI jobs for older node.js versions run + // `jest` against the compiled .js results (would require compiling + // the test files as well)? + 'unicorn/prefer-at': 'off', + } + } + ], + rules: { curly: 'error', // Enforce braces on "if"/"for"/etc. // Avoid accidental use of "==" instead of "===". diff --git a/packages/neovim/src/api/Tabpage.test.ts b/packages/neovim/src/api/Tabpage.test.ts index 1b48f0c9..2f0d6add 100644 --- a/packages/neovim/src/api/Tabpage.test.ts +++ b/packages/neovim/src/api/Tabpage.test.ts @@ -65,7 +65,7 @@ describe('Tabpage API', () => { const tabpages = await nvim.tabpages; expect(tabpages.length).toBe(2); - nvim.tabpage = tabpages.at(-1); + nvim.tabpage = tabpages[tabpages.length - 1]; const newTabPage = await nvim.tabpage; expect(await newTabPage.number).toBe(2); @@ -139,7 +139,7 @@ describe('Tabpage API', () => { // TODO expect((await nvim.tabpages).length).toBe(2); - nvim.tabpage = tabpages.at(-1); + nvim.tabpage = tabpages[tabpages.length - 1]; expect(await nvim.tabpage.number).toBe(2); });