Skip to content

Commit

Permalink
Make tests run with skips on node 18
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Feb 23, 2024
1 parent 91705ed commit e3d6f1b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ console.log(trace("123"));
## Notes:

- This currently is only tested on Node 18+, no browser version yet.
- `--experimental-vm-modules` is required for the async versions that
allow importing libraries.
- Node 20.8+ and `--experimental-vm-modules` are required for the async
versions that allow importing libraries.
- This is for NON-performance-sensitive code (e.g. prototypes), because the
parser with be generated every time the template is evaluated.
- If your parse function's variable name has exactly five letters (like
Expand Down
7 changes: 7 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mod from "@peggyjs/eslint-config/flat/module.js";
import modern from "@peggyjs/eslint-config/flat/modern.js";
import peggyjs from "@peggyjs/eslint-plugin/lib/flat/recommended.js";

export default [
Expand All @@ -11,4 +12,10 @@ export default [
},
mod,
peggyjs,
{
files: [
"test/**",
],
modern,
},
];
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@peggyjs/eslint-plugin": "2.0.0",
"@types/node": "20.11.20",
"c8": "9.1.0",
"semver": "7.6.0",
"typescript": "5.3.3"
},
"packageManager": "[email protected]",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 22 additions & 6 deletions test/index-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { default as peggy, withImports } from "../lib/index.js";
import assert from "node:assert";
import semver from "semver";
import test from "node:test";

// Don't syntax-highlight the intentionally-invalid code.
Expand All @@ -15,15 +16,15 @@ test("bad grammar", () => {
() => bad`foo = "foo`,
// The position of the dquote in the line above. This will change
// if the line above moves in the file.
/index-spec\.js:15:21\n \|\n15 \| foo = "foo\n \| \^/
/index-spec\.js:16:21\n \|\n16 \| foo = "foo\n \| \^/
);
});

test("bad input", () => {
const parser = peggy`foo = "foo"`;
assert.throws(
() => parser("bar"), // This is line 25
/^25 \| bar/m
() => parser("bar"), // This is line 26
/^26 \| bar/m
);
});

Expand All @@ -41,21 +42,36 @@ test("with options", () => {
assert(events.length > 0);
});

test("with library", async() => {
test("with library", async t => {
if (!semver.satisfies(process.version, ">=20.8")) {
t.skip("Requires node 20.8+");
return;
}

const parser = await withImports`
import Foo from "./fixtures/foo.js"
Bar = Foo`;

assert.equal(parser("foo"), "foo");
});

test("with library, errors", async() => {
test("with library, errors", async t => {
if (!semver.satisfies(process.version, ">=20.8")) {
t.skip("Requires node 20.8+");
return;
}

await assert.rejects(() => withImports`
import Boo from "./fixtures/foo.js"
Bar = Foo`);
});

test("with library and options", async() => {
test("with library and options", async t => {
if (!semver.satisfies(process.version, ">=20.8")) {
t.skip("Requires node 20.8+");
return;
}

const peg = peggy.withImportsOptions({ trace: true });
const parser = await peg`
import Foo from "./fixtures/foo.js"
Expand Down

0 comments on commit e3d6f1b

Please sign in to comment.