Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"@rollup/plugin-typescript": "^11.1.6",
"@types/chai": "^4.3.11",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.30",
"@types/node": "^24.2.0",
"@types/require-from-string": "^1.2.3",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
Expand All @@ -94,7 +94,6 @@
"eslint-config-prettier": "^9.1.0",
"glob": "^10.3.10",
"husky": "^9.0.11",
"if-node-version": "^1.1.1",
"jimp": "^0.22.10",
"js-beautify": "^1.15.1",
"json-schema-test": "^2.0.0",
Expand All @@ -103,7 +102,6 @@
"karma-mocha": "^2.0.1",
"lint-staged": "^15.2.2",
"mocha": "^10.3.0",
"module-from-string": "^3.3.0",
"node-fetch": "^3.3.2",
"nyc": "^15.1.0",
"prettier": "3.0.3",
Expand Down
4 changes: 2 additions & 2 deletions spec/issues/1683_re2_engine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import jsonSchemaTest = require("json-schema-test")
import options from "../ajv_options"
import {afterError, afterEach} from "../after_test"
import chai from "../chai"
import re2 from "../../dist/runtime/re2"
// import re2 from "../../dist/runtime/re2"
import re2tests from "./re2"

const instances = getAjvAllInstances(options, {
Expand All @@ -18,7 +18,7 @@ const instances = getAjvAllInstances(options, {
instances.forEach((ajv) => {
ajv.opts.code.source = true
ajv.opts.code.formats = _`{allowedUnknown: true}`
ajv.opts.code.regExp = re2
// ajv.opts.code.regExp = re2
})

jsonSchemaTest(withStandalone(instances), {
Expand Down
3 changes: 1 addition & 2 deletions spec/keyword.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type AjvCore from "../dist/core"
import {_, nil} from "../dist/compile/codegen/code"
import getAjvAllInstances from "./ajv_all_instances"
import _Ajv from "./ajv"
import equal from "../dist/runtime/equal"
import assert = require("assert")
import chai from "./chai"
const should = chai.should()
Expand Down Expand Up @@ -234,7 +233,7 @@ describe("User-defined keywords", () => {
return typeof schema == "object" && schema !== null ? isDeepEqual : isStrictEqual

function isDeepEqual(data) {
return equal(data, schema)
return assert.deepEqual(data, schema)
}
function isStrictEqual(data) {
return data === schema
Expand Down
16 changes: 11 additions & 5 deletions spec/standalone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import _Ajv from "./ajv"
import standaloneCode from "../dist/standalone"
import ajvFormats from "@theflashlabs/ajv-formats"
import requireFromString = require("require-from-string")
import {importFromStringSync} from "module-from-string"
import assert = require("assert")

async function importFromStringSync(codeString) {
const dataUrl = `data:text/javascript,${encodeURIComponent(codeString)}`
const module = await import(dataUrl)
return module
}

function testExportTypeEsm(moduleCode: string, singleExport: boolean) {
//Must have
assert.strictEqual(moduleCode.includes("export const"), true)
Expand Down Expand Up @@ -56,7 +61,7 @@ describe("standalone code generation", () => {
testExports(m)
})

it("should generate module code with named export - ESM", () => {
it("should generate module code with named export - ESM", async () => {
ajv = new _Ajv({code: {source: true, esm: true}})
ajv.addSchema(numSchema)
ajv.addSchema(strSchema)
Expand All @@ -65,7 +70,8 @@ describe("standalone code generation", () => {
validateString: "https://example.com/string.json",
})
testExportTypeEsm(moduleCode, false)
const m = importFromStringSync(moduleCode)
const m = await importFromStringSync(moduleCode)
console.log("importFromStringSync: ", m)
assert.strictEqual(Object.keys(m).length, 2)
testExports(m)
})
Expand Down Expand Up @@ -301,15 +307,15 @@ describe("standalone code generation", () => {
}
})

it("should generate module code with a single export - ESM", () => {
it("should generate module code with a single export - ESM", async () => {
const ajv = new _Ajv({code: {source: true, esm: true}})
const v = ajv.compile({
type: "number",
minimum: 0,
})
const moduleCode = standaloneCode(ajv, v)
testExportTypeEsm(moduleCode, true)
const m = importFromStringSync(moduleCode)
const m = await importFromStringSync(moduleCode)
testExport(m.validate)
testExport(m.default)

Expand Down
Loading
Loading