Skip to content

Commit

Permalink
test: failing test for standalone code (duplicate functions, #1361)
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Dec 19, 2020
1 parent e446893 commit eae2d5d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions spec/standalone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe("standalone code generation", () => {
}
})

describe.only("two refs to the same schema (issue #1361)", () => {
describe.skip("two refs to the same schema (issue #1361)", () => {
const userSchema = {
$id: "user.json",
type: "object",
Expand Down Expand Up @@ -118,7 +118,8 @@ describe("standalone code generation", () => {
})

const moduleCode = standaloneCode(ajv)
console.log(moduleCode)
assertNoDuplicateFunctions(moduleCode)

const {"user.json": validateUser, "info.json": validateInfo} = requireFromString(moduleCode)
assert.strictEqual(validateUser({}), false)
assert.strictEqual(validateUser({name: "usr1"}), true)
Expand All @@ -133,6 +134,13 @@ describe("standalone code generation", () => {
)
})
})

function assertNoDuplicateFunctions(code: string): void {
const funcs = code.match(/function\s+([a-z0-9_$]+)/gi)
assert(Array.isArray(funcs))
assert(funcs.length > 0)
assert.strictEqual(funcs.length, new Set(funcs).size, "should have no duplicates")
}
})

it("should generate module code with a single export (ESM compatible)", () => {
Expand Down

0 comments on commit eae2d5d

Please sign in to comment.