Skip to content

Commit

Permalink
build: test code must run in older node.js
Browse files Browse the repository at this point in the history
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[…]`).
  • Loading branch information
justinmk committed Feb 3, 2024
1 parent 1d61403 commit 56fefb9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "===".
Expand Down
4 changes: 2 additions & 2 deletions packages/neovim/src/api/Tabpage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit 56fefb9

Please sign in to comment.