Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

no-disabled.test.js

473 lines20.5 KB

1import { describe, it } from 'vitest'
2import { RuleTester } from 'eslint'
3import tsParser from '@typescript-eslint/parser'
4import noDisabled from './rules/no-disabled.js'
5​
6RuleTester.describe = describe
7RuleTester.it = it
8​
9const ruleTester = new RuleTester({
10 languageOptions: { parser: tsParser },
11})
12​
13ruleTester.run(`oracle/no-disabled`, noDisabled, {
14 valid: [
15 // A selection helper's result used as a registration, with no modifier.
16 {
17 code: `import { oracleReplayTest } from './oracle-config.js'\nimport { it as vitestIt } from 'vitest'\nconst fixedCase = oracleReplayTest(vitestIt)\nfixedCase('checks the fixed history', () => check(history))`,
18 languageOptions: { sourceType: `module` },
19 },
20 // A constant that is not bound to a test function registers nothing.
21 {
22 code: `const helper = makeHelper()\nhelper.skip('a', () => check())`,
23 languageOptions: { sourceType: `module` },
24 },
25 // The shared replay variables, and variables that select no replay.
26 `const seed = process.env.TANSTACK_DB_ORACLE_SEED`,
27 `const { TANSTACK_DB_ORACLE_PATH, TANSTACK_DB_ORACLE_PROPERTY } = process.env`,
28 `const statistics = process.env.TANSTACK_DB_ORACLE_STATISTICS`,
29 `const debug = process.env.RELOAD_ORACLE_DEBUG`,
30 `const seed = config.TANSTACK_DB_LIKE_ORACLE_SEED`,
31 // oracle-config implements replay selection, so it reads every variable.
32 {
33 code: `const seed = process.env.UTILS_ORACLE_SEED`,
34 filename: `/repo/packages/db/tests/oracle-config.ts`,
35 },
36 // A replay that does not select this property registers an empty test.
37 `it.skip('runs only when its replay property is selected', () => {})`,
38 `it.todo('loads every subset from one generation')`,
39 // Playwright's runtime skip for a control that one browser supports.
40 `test.skip(browserName !== 'chromium', 'Chromium-only control')`,
41 // A replay campaign stands the other tests aside.
42 {
43 code: `import { oracleReplayRequested } from '../../db/tests/oracle-config.js'\nit.skipIf(oracleReplayRequested())('checks the history', () => check())`,
44 languageOptions: { sourceType: `module` },
45 },
46 {
47 code: `import { oracleReplayRequested } from './oracle-config'\nit.skipIf(oracleReplayRequested())('checks the history', () => check())`,
48 languageOptions: { sourceType: `module` },
49 },
50 `fc.assert(property, oraclePropertyOptions(12, 'cleanup-queue.history'))`,
51 `fc.assert(property, { numRuns: oracleRuns(20) })`,
52 `const BINDING_RUNS = 12\nfc.assert(property, { numRuns: oracleRuns(BINDING_RUNS) })`,
53 `const fixedSeed = 7\nconst runs = 30\nfc.assert(property, { seed: fixedSeed, numRuns: runs })`,
54 // A replay passes the recorded path, and a witness a fixed seed.
55 `fc.check(property, { seed: failed.seed, path: failed.counterexamplePath, numRuns: 1 })`,
56 `fc.check(property, { seed: 205203, numRuns: 1 })`,
57 `fc.check(property, { seed: -1659005, numRuns: 1 })`,
58 `const fixedSeed = 1657019\nfc.check(property, { seed: fixedSeed, numRuns: 1 })`,
59 `fc.assert(property, { seed: 2128, numRuns: oracleRuns(1) })`,
60 // An expectation about a recorded run is not a run option, and a sample
61 // runs no property.
62 `expect(report).toMatchObject({ numRuns: 1, failed: true })`,
63 `fc.sample(historyArbitrary, { numRuns: 1 })`,
64 // A known gap is pinned as failing on a fixed seed, not skipped.
65 `it.fails('checks the fixed history', () => fc.assert(property, { seed: 2128, numRuns: oracleRuns(12) }))`,
66 // The shared replay helpers may select a replay, in either polarity for
67 // a registration and through the alias helper.
68 ...[
69 `it.skipIf(oracleReplaySkips('cursor.exact-width'))('a', () => check())`,
70 `if (!oracleReplayRequested()) { it('a', () => check()) }`,
71 `if (oracleReplayRequested()) { replayOnly() } else { it('a', () => check()) }`,
72 `const propertyTest = oracleReplayTest(fcTest, 'cursor.exact-width')\npropertyTest.prop([a])('a', check)`,
73 `describe('s', () => { if (oracleReplaySkips('cursor.exact-width')) return\n it('a', () => check()) })`,
74 ].map((code) => ({
75 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\n${code}`,
76 languageOptions: { sourceType: `module` },
77 })),
78 // Playwright's test API calls that register nothing.
79 `test('a', async () => { if (rejected) { expect(test.info().project.name).not.toBe('webkit') } })`,
80 // A guard that skips a loop item filters data, as \`.filter\` would.
81 `for (const c of cases) { if (!c.legal) continue\n it(c.name, () => check(c)) }`,
82 // A loop over a table that a replay helper empties during a replay, and a
83 // data filter, run every item in ordinary runs.
84 ...[
85 `for (const c of oracleReplayRequested() ? [] : cases) { it(c.name, () => check(c)) }`,
86 `it.each(cases.filter((c) => c.legal))('%s', (c) => check(c))`,
87 `const campaigns = oracleReplaySkips('cursor.exact-width') ? [] : cases\nfor (const c of campaigns) { it(c.name, () => check(c)) }`,
88 `const registration = oracleReplayTest(it)\nregistration('a', () => check())`,
89 ].map((code) => ({
90 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\n${code}`,
91 languageOptions: { sourceType: `module` },
92 })),
93 // Registrations in a loop or over a table run in every ordinary run.
94 `for (const campaign of campaigns) { it(campaign.name, () => check(campaign)) }`,
95 `const fixedRuns = { seed: 1846, numRuns: 40 }`,
96 // A skip on something other than the test context is not a test skip.
97 `it('reads a page', (ctx) => { const cursor = open(); cursor.skip() })`,
98 // An inner variable that shadows the context is not the test context.
99 `it('reads a page', (ctx) => { pages.forEach((ctx) => ctx.skip()) })`,
100 `it('reads a page', (_, ctx) => { ctx.skip() })`,
101 ],
102 invalid: [
103 // A private variable that selects a replay or a run count.
104 {
105 code: `const seed = process.env.TANSTACK_DB_LIKE_ORACLE_SEED`,
106 errors: [
107 {
108 messageId: `replayVariable`,
109 data: { name: `TANSTACK_DB_LIKE_ORACLE_SEED` },
110 },
111 ],
112 },
113 {
114 code: `fc.assert(property, { path: process.env['BTREE_MAP_ORACLE_PATH'] })`,
115 errors: [{ messageId: `replayVariable` }],
116 },
117 {
118 code: `const runs = Number(process.env.TANSTACK_DB_OPFS_CLOSE_ORACLE_RUNS ?? 20)`,
119 errors: [{ messageId: `replayVariable` }],
120 },
121 {
122 code: `const { INDEXEDDB_ORACLE_SEED: seed, TANSTACK_DB_ORACLE_PATH } = process.env`,
123 errors: [
124 {
125 messageId: `replayVariable`,
126 data: { name: `INDEXEDDB_ORACLE_SEED` },
127 },
128 ],
129 },
130 {
131 code: `const property = process.env.UTILS_ORACLE_PROPERTY`,
132 filename: `/repo/packages/db/tests/utils-oracle.property.test.ts`,
133 errors: [{ messageId: `replayVariable` }],
134 },
135 {
136 code: `it.only('checks the history', () => {})`,
137 errors: [{ messageId: `only` }],
138 },
139 {
140 code: `describe.only('cleanup queue', () => { it('a', () => {}) })`,
141 errors: [{ messageId: `only` }],
142 },
143 {
144 code: `fcTest.only.prop([history])('checks the history', (h) => check(h))`,
145 errors: [{ messageId: `only` }],
146 },
147 {
148 code: `it.skip('checks random histories', () => fc.assert(property))`,
149 errors: [{ messageId: `skip`, data: { name: `skip` } }],
150 },
151 {
152 code: `describe.skip('cleanup queue', () => { it('a', () => check()) })`,
153 errors: [{ messageId: `skip` }],
154 },
155 {
156 code: `fcTest.skip.prop([history])('checks the history', (h) => check(h))`,
157 errors: [{ messageId: `skip` }],
158 },
159 {
160 code: `it.skip('checks follower histories', assertFollowerHistory)`,
161 errors: [{ messageId: `skip` }],
162 },
163 {
164 code: `fcTest.skip.prop([history])('checks the history', checkHistory)`,
165 errors: [{ messageId: `skip` }],
166 },
167 {
168 code: `test.skip()`,
169 errors: [{ messageId: `skip` }],
170 },
171 {
172 code: `test.skip(true, 'flaky in CI')`,
173 errors: [{ messageId: `skip` }],
174 },
175 {
176 code: `it.skipIf(true)('checks the history', () => check())`,
177 errors: [{ messageId: `conditional`, data: { name: `skipIf` } }],
178 },
179 {
180 code: `describe.runIf(false)('cleanup queue', () => { it('a', () => check()) })`,
181 errors: [{ messageId: `conditional`, data: { name: `runIf` } }],
182 },
183 {
184 code: `describe.skipIf(process.env.CI)('cleanup queue', () => { it('a', () => check()) })`,
185 errors: [{ messageId: `conditional` }],
186 },
187 {
188 code: `it.todo('checks the history', () => { check() })`,
189 errors: [{ messageId: `skip`, data: { name: `todo` } }],
190 },
191 {
192 code: `fc.assert(property, { numRuns: 1 })`,
193 errors: [{ messageId: `singleRun` }],
194 },
195 {
196 code: `fc.assert(property, { ...oraclePropertyOptions(100, 'p'), numRuns: 1 })`,
197 errors: [{ messageId: `singleRun` }],
198 },
199 {
200 code: `fc.assert(property, oraclePropertyOptions(1, 'cleanup-queue.history'))`,
201 errors: [{ messageId: `singleRun` }],
202 },
203 {
204 code: `fc.assert(property, { seed: Date.now(), numRuns: 1 })`,
205 errors: [{ messageId: `singleRun` }],
206 },
207 {
208 code: `fc.assert(property, { seed: undefined, numRuns: 1 })`,
209 errors: [{ messageId: `singleRun` }],
210 },
211 {
212 code: `fc.assert(property, filePath ? { numRuns: 1 } : {})`,
213 errors: [{ messageId: `singleRun` }],
214 },
215 {
216 code: `it.skipIf(useFilePath)('checks the history', () => check())`,
217 errors: [{ messageId: `conditional` }],
218 },
219 {
220 code: `fc.assert(property, { numRuns: oracleRuns(0) })`,
221 errors: [{ messageId: `singleRun` }],
222 },
223 {
224 code: `test.skip(isMobile)`,
225 errors: [{ messageId: `skip` }],
226 },
227 {
228 code: `test.skip(process.env.CI === 'true', 'flaky')`,
229 errors: [{ messageId: `skip` }],
230 },
231 {
232 code: `test.fixme('checks the history', check)`,
233 errors: [{ messageId: `skip`, data: { name: `fixme` } }],
234 },
235 {
236 code: `test.describe.fixme('cleanup queue', () => { test('a', check) })`,
237 errors: [{ messageId: `skip`, data: { name: `fixme` } }],
238 },
239 {
240 code: `test.fixme()`,
241 errors: [{ messageId: `skip`, data: { name: `fixme` } }],
242 },
243 {
244 code: `it('checks the history', (ctx) => { ctx.skip(); check() })`,
245 errors: [{ messageId: `skip` }],
246 },
247 {
248 code: `it('checks the history', (ctx) => { steps.forEach(() => ctx.skip()) })`,
249 errors: [{ messageId: `skip` }],
250 },
251 {
252 // A local function with the helper's name is not the shared helper.
253 code: `const oracleReplayRequested = () => process.env.CI === 'true'\nit.skipIf(oracleReplayRequested())('checks the history', () => check())`,
254 errors: [{ messageId: `conditional` }],
255 },
256 {
257 code: `it.skipIf(oracleReplayRequested())('checks the history', () => check())`,
258 errors: [{ messageId: `conditional` }],
259 },
260 {
261 // Only the shared helper may select a replay: its polarity is fixed.
262 code: `it.skipIf(replayRequested)('checks the history', () => check())`,
263 errors: [{ messageId: `conditional` }],
264 },
265 {
266 code: `it.runIf(replay.replayPath === undefined)('checks the history', () => check())`,
267 errors: [{ messageId: `conditional`, data: { name: `runIf` } }],
268 },
269 {
270 code: `it.runIf(replay.replayPath !== undefined)('checks the history', check)`,
271 errors: [{ messageId: `conditional` }],
272 },
273 {
274 code: `describe.skipIf(!oracleReplayRequested())('cleanup queue', () => { it('a', () => check()) })`,
275 errors: [{ messageId: `conditional` }],
276 },
277 {
278 code: `describe.skipIf(path.sep === '\\\\')('cleanup queue', () => { it('a', () => check()) })`,
279 errors: [{ messageId: `conditional` }],
280 },
281 {
282 code: `fc.assert(property, replayRequested ? {} : { numRuns: 1 })`,
283 errors: [{ messageId: `singleRun` }],
284 },
285 {
286 code: `fc.assert(property, campaign === 'replay' ? { numRuns: 1 } : {})`,
287 errors: [{ messageId: `singleRun` }],
288 },
289 {
290 code: `fc.assert(property, { seed: process.env.SEED, numRuns: 1 })`,
291 errors: [{ messageId: `singleRun` }],
292 },
293 {
294 code: `fc.assert(property, { seed: replay.replaySeed, numRuns: 1 })`,
295 errors: [{ messageId: `singleRun` }],
296 },
297 {
298 code: `let seed = 1\nfc.assert(property, { seed, numRuns: 1 })`,
299 errors: [{ messageId: `singleRun` }],
300 },
301 {
302 code: `fc.assert(property, { seed: replay.replaySeed, path: undefined, numRuns: 1 })`,
303 errors: [{ messageId: `singleRun` }],
304 },
305 {
306 code: `const propertyTest = replay.replayPath === undefined ? fcTest : fcTest.skip`,
307 errors: [
308 { messageId: `aliasTest`, data: { name: `fcTest` } },
309 { messageId: `alias`, data: { name: `skip` } },
310 ],
311 },
312 {
313 code: `const run = it.skip\nrun('a', () => check())`,
314 errors: [{ messageId: `alias` }],
315 },
316 {
317 code: `const run = fcTest.skip.prop([a])\nrun('a', check)`,
318 errors: [{ messageId: `skip` }],
319 },
320 {
321 code: `if (!replayRequested) { it('a', () => check()) }`,
322 errors: [{ messageId: `guarded` }],
323 },
324 {
325 code: `describe('s', () => { if (requested !== id) { return }\n it('a', () => check()) })`,
326 errors: [{ messageId: `guarded` }],
327 },
328 {
329 code: `process.env.CI || it('a', () => check())`,
330 errors: [{ messageId: `guarded` }],
331 },
332 {
333 code: `const oracleReplayRequested = () => true\nif (!oracleReplayRequested()) { it('a', () => check()) }`,
334 errors: [{ messageId: `guarded` }],
335 },
336 {
337 code: `fc.assert(property, { seed: replay.replaySeed, path: replay.replayPath, numRuns: 1 })`,
338 errors: [{ messageId: `singleRun` }],
339 },
340 {
341 code: `fc.assert(property, { numRuns: 300 })`,
342 errors: [{ messageId: `literalRuns` }],
343 },
344 {
345 code: `fcTest.prop([history], { numRuns: 200 })('checks the history', check)`,
346 errors: [{ messageId: `literalRuns` }],
347 },
348 {
349 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\nif (process.env.CI) { oracleReplayTest(it)('a', () => check()) }`,
350 languageOptions: { sourceType: `module` },
351 errors: [{ messageId: `guarded` }],
352 },
353 {
354 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\noracleReplayTest(it).only('a', () => check())`,
355 languageOptions: { sourceType: `module` },
356 errors: [{ messageId: `only` }],
357 },
358 {
359 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\noracleReplayTest(it).skip('a', () => check())`,
360 languageOptions: { sourceType: `module` },
361 errors: [{ messageId: `skip` }],
362 },
363 {
364 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\noracleReplayTest(it).skipIf(process.env.CI)('a', () => check())`,
365 languageOptions: { sourceType: `module` },
366 errors: [{ messageId: `conditional` }],
367 },
368 {
369 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\nif (oracleReplayRequested()) { it('law', () => check()) }`,
370 languageOptions: { sourceType: `module` },
371 errors: [{ messageId: `guarded` }],
372 },
373 {
374 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\ndescribe('s', () => { if (!oracleReplayRequested()) return\n it('a', () => check()) })`,
375 languageOptions: { sourceType: `module` },
376 errors: [{ messageId: `guarded` }],
377 },
378 {
379 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\noracleReplayRequested() && it('law', () => check())`,
380 languageOptions: { sourceType: `module` },
381 errors: [{ messageId: `guarded` }],
382 },
383 {
384 code: `const BINDING_RUNS = 12\nfc.assert(property, { numRuns: BINDING_RUNS })`,
385 errors: [{ messageId: `literalRuns` }],
386 },
387 {
388 code: `const replayRuns = 1\nfc.assert(property, { numRuns: replayRuns })`,
389 errors: [{ messageId: `singleRun` }],
390 },
391 {
392 code: `const base = 1\nfc.assert(property, oraclePropertyOptions(base, 'p'))`,
393 errors: [{ messageId: `singleRun` }],
394 },
395 {
396 // The rule reports the alias, and it also sees the skip through it.
397 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\nconst t = it\nt.skip('a', () => check())`,
398 languageOptions: { sourceType: `module` },
399 errors: [{ messageId: `aliasTest` }, { messageId: `skip` }],
400 },
401 // A registration through a selection helper's result is a registration of
402 // its test, so its modifiers and guards are checked.
403 {
404 code: `import { oracleReplayTest } from './oracle-config.js'\nconst fixedCase = oracleReplayTest(it)\nfixedCase.skip('checks the fixed history', () => check(history))`,
405 languageOptions: { sourceType: `module` },
406 errors: [{ messageId: `skip` }],
407 },
408 {
409 code: `import { oracleReplayTest } from './oracle-config.js'\nconst fixedCase = oracleReplayTest(it)\nfixedCase.only('checks the fixed history', () => check(history))`,
410 languageOptions: { sourceType: `module` },
411 errors: [{ messageId: `only` }],
412 },
413 {
414 code: `import { oracleReplayTest } from './oracle-config.js'\nconst fixedCase = oracleReplayTest(it)\nif (process.env.CI) fixedCase('checks the fixed history', () => check(history))`,
415 languageOptions: { sourceType: `module` },
416 errors: [{ messageId: `guarded` }],
417 },
418 {
419 code: `import { oracleCalibrationTest } from './oracle-config.js'\nconst witness = oracleCalibrationTest(it, 'p', 'fault')\nconst again = witness\nagain.skipIf(process.env.CI)('rejects the mutant', () => check(bad))`,
420 languageOptions: { sourceType: `module` },
421 errors: [{ messageId: `conditional` }],
422 },
423 // A renamed import of a test function is that test function.
424 {
425 code: `import { it as vitestIt } from 'vitest'\nvitestIt.skip('checks a history', () => check(history))`,
426 languageOptions: { sourceType: `module` },
427 errors: [{ messageId: `skip` }],
428 },
429 {
430 code: `import { oracleReplayTest } from './oracle-config.js'\nimport { test as fcTestAlias } from '@fast-check/vitest'\nconst campaign = oracleReplayTest(fcTestAlias, 'p')\ncampaign.todo.prop([history])('checks histories', (h) => check(h))`,
431 languageOptions: { sourceType: `module` },
432 errors: [{ messageId: `skip` }],
433 },
434 {
435 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\nconst tests = [it, test]\ntests[0]('a', () => check())`,
436 languageOptions: { sourceType: `module` },
437 errors: [{ messageId: `aliasTest` }, { messageId: `aliasTest` }],
438 },
439 {
440 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\nfor (const c of process.env.CI ? [] : cases) { it(c.name, () => check(c)) }`,
441 languageOptions: { sourceType: `module` },
442 errors: [{ messageId: `guarded` }],
443 },
444 {
445 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\nfor (const c of cases.filter(() => !process.env.CI)) { it(c.name, () => check(c)) }`,
446 languageOptions: { sourceType: `module` },
447 errors: [{ messageId: `guarded` }],
448 },
449 {
450 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\nit.each(process.env.CI ? [] : cases)('%s', (c) => check(c))`,
451 languageOptions: { sourceType: `module` },
452 errors: [{ messageId: `guarded` }],
453 },
454 {
455 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\nconst campaigns = process.env.CI ? [] : cases\nfor (const c of campaigns) { it(c.name, () => check(c)) }`,
456 languageOptions: { sourceType: `module` },
457 errors: [{ messageId: `guarded` }],
458 },
459 {
460 code: `import { oracleReplayRequested, oracleReplaySkips, oracleReplayTest } from './oracle-config.js'\nfor (const c of oracleReplayRequested() ? cases : []) { it(c.name, () => check(c)) }`,
461 languageOptions: { sourceType: `module` },
462 errors: [{ messageId: `guarded` }],
463 },
464 {
465 // A comment does not grant an exception.
466 code: `
467 // oracle-exclusion: known gap
468 it.skip('checks random histories', () => fc.assert(property))
469 `,
470 errors: [{ messageId: `skip` }],
471 },
472 ],
473})