Skip to content

Commit 74f5e9a

Browse files
committed
fix: coverage
1 parent 0a2657d commit 74f5e9a

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ jobs:
1515
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
1616
with:
1717
license-check: true
18+
lint: true

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"main": "index.js",
66
"types": "index.d.ts",
77
"scripts": {
8+
"lint": "standard",
89
"lint:fix": "standard --fix",
9-
"unit": "tap --100 test/**/*.test.js",
10-
"test": "standard && npm run unit && npm run test:typescript",
10+
"unit": "tap test/**/*.test.js",
11+
"test": "npm run unit && npm run test:typescript",
12+
"posttest": "rm test/fjs-generated*.js",
1113
"test:typescript": "tsd"
1214
},
1315
"repository": {

standalone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function StandaloneValidator (options = { readMode: true }) {
2323
// WRITE MODE: it behalf on the default SerializerSelector, wrapping the API to run the Ajv Standalone code generation
2424
const factory = SerializerSelector()
2525
return function wrapper (externalSchemas, serializerOpts = {}) {
26-
if (!serializerOpts.mode || !serializerOpts.mode !== 'standalone') {
26+
if (!serializerOpts.mode || serializerOpts.mode !== 'standalone') {
2727
// to generate the serialization source code, these options are mandatory
2828
serializerOpts.mode = 'standalone'
2929
}

test/standalone.test.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,30 @@ t.test('fastify integration - writeMode', async t => {
103103
await app.ready()
104104
})
105105

106+
t.test('fastify integration - writeMode forces standalone', async t => {
107+
t.plan(4)
108+
109+
const factory = FjsStandaloneCompiler({
110+
readMode: false,
111+
storeFunction (routeOpts, schemaSerializationCode) {
112+
const fileName = generateFileName(routeOpts)
113+
t.ok(routeOpts)
114+
fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode)
115+
t.pass(`stored the validation function ${fileName}`)
116+
},
117+
restoreFunction () {
118+
t.fail('write mode ON')
119+
}
120+
})
121+
122+
const app = buildApp(factory, {
123+
mode: 'not-standalone',
124+
rounding: 'ceil'
125+
})
126+
127+
await app.ready()
128+
})
129+
106130
t.test('fastify integration - readMode', async t => {
107131
t.plan(6)
108132

@@ -136,15 +160,16 @@ t.test('fastify integration - readMode', async t => {
136160
t.equal(res.payload, JSON.stringify({ lang: 'en' }))
137161
})
138162

139-
function buildApp (factory) {
163+
function buildApp (factory, serializerOpts) {
140164
const app = fastify({
141165
exposeHeadRoutes: false,
142166
jsonShorthand: false,
143167
schemaController: {
144168
compilersFactory: {
145169
buildSerializer: factory
146170
}
147-
}
171+
},
172+
serializerOpts
148173
})
149174

150175
app.addSchema({

0 commit comments

Comments
 (0)