Skip to content

Commit 643cf15

Browse files
test(shared-data): Continue testing other labware if one test fails (#17420)
* When we're iterating over labware definition files to test, instead of using a JavaScript-level `forEach`, use a Vitest-level `it.each` or `test.each`. This just makes the error reporting a little bit better: if multiple labware definitions have errors, Vitest will now detect and print all of them instead of just the first one. * Adjust messages and swap some things between `it` and `test`. This is just for code readability and does not have any functional difference.
1 parent cffab4e commit 643cf15

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

shared-data/js/__tests__/labwareDefSchemaV1.test.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path'
22
import glob from 'glob'
33
import Ajv from 'ajv'
4-
import { describe, expect, it, beforeAll } from 'vitest'
4+
import { describe, expect, it, test } from 'vitest'
55

66
import { labwareSchemaV1 } from '../schema'
77
import type { LabwareDefinition1 } from '../types'
@@ -57,26 +57,25 @@ describe('test the schema against a minimalist fixture', () => {
5757
})
5858
})
5959

60-
describe('test schemas of all definitions', () => {
60+
describe('test all definitions', () => {
6161
const labwarePaths = glob.sync(DEFINITIONS_GLOB_PATTERN, GLOB_OPTIONS)
6262

63-
beforeAll(() => {
64-
// Make sure definitions path didn't break, which would give you false positives
63+
test("definition paths didn't break, which would give false positives", () => {
6564
expect(labwarePaths.length).toBeGreaterThan(0)
6665
})
6766

68-
labwarePaths.forEach(labwarePath => {
67+
describe.each(labwarePaths)('%s', labwarePath => {
6968
const filename = path.parse(labwarePath).name
7069
const labwareDef = require(labwarePath) as LabwareDefinition1
7170

72-
it(filename, () => {
71+
it('validates against the schema', () => {
7372
const valid = validate(labwareDef)
7473
const validationErrors = validate.errors
7574
expect(validationErrors).toBe(null)
7675
expect(valid).toBe(true)
7776
})
7877

79-
it(`file name matches metadata.name: ${filename}`, () => {
78+
it(`has a file name that matches metadata.name: ${filename}`, () => {
8079
expect(labwareDef.metadata.name).toEqual(filename)
8180
})
8281
})

shared-data/js/__tests__/labwareDefSchemaV2.test.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -197,34 +197,33 @@ test('fail on bad labware', () => {
197197
describe('test schemas of all opentrons definitions', () => {
198198
const labwarePaths = glob.sync(globPattern, { cwd: definitionsDir })
199199

200-
beforeAll(() => {
201-
// Make sure definitions path didn't break, which would give you false positives
200+
test("definition paths didn't break, which would give false positives", () => {
202201
expect(labwarePaths.length).toBeGreaterThan(0)
203202
})
204203

205-
labwarePaths.forEach(labwarePath => {
204+
describe.each(labwarePaths)('%s', labwarePath => {
206205
const filename = path.parse(labwarePath).base
207206
const fullLabwarePath = path.join(definitionsDir, labwarePath)
208207
const labwareDef = require(fullLabwarePath) as LabwareDefinition2
209208

210-
it(`${filename} validates against schema`, () => {
209+
it('validates against the schema', () => {
211210
const valid = validate(labwareDef)
212211
const validationErrors = validate.errors
213212
expect(validationErrors).toBe(null)
214213
expect(valid).toBe(true)
215214
})
216215

217-
it(`file name matches version: ${labwarePath}`, () => {
216+
test('file name matches version', () => {
218217
expect(`${labwareDef.version}`).toEqual(path.basename(filename, '.json'))
219218
})
220219

221-
it(`parent dir matches loadName: ${labwarePath}`, () => {
220+
test('parent dir matches loadName', () => {
222221
expect(labwareDef.parameters.loadName).toEqual(
223222
path.basename(path.dirname(labwarePath))
224223
)
225224
})
226225

227-
it(`namespace is "opentrons": ${labwarePath}`, () => {
226+
test('namespace is "opentrons"', () => {
228227
expect(labwareDef.namespace).toEqual('opentrons')
229228
})
230229

@@ -266,30 +265,29 @@ describe('test that the dimensions in all opentrons definitions make sense', ()
266265
describe('test schemas of all v2 labware fixtures', () => {
267266
const labwarePaths = glob.sync(globPattern, { cwd: fixturesDir })
268267

269-
beforeAll(() => {
270-
// Make sure fixtures path didn't break, which would give you false positives
268+
test("definition paths didn't break, which would give false positives", () => {
271269
expect(labwarePaths.length).toBeGreaterThan(0)
272270
})
273271

274-
labwarePaths.forEach(labwarePath => {
272+
describe.each(labwarePaths)('%s', labwarePath => {
275273
const filename = path.parse(labwarePath).base
276274
const fullLabwarePath = path.join(fixturesDir, labwarePath)
277275
const labwareDef = require(fullLabwarePath) as LabwareDefinition2
278276

279-
it(`${filename} validates against schema`, () => {
277+
test(`${filename} validates against schema`, () => {
280278
const valid = validate(labwareDef)
281279
const validationErrors = validate.errors
282280
expect(validationErrors).toBe(null)
283281
expect(valid).toBe(true)
284282
})
285283

286-
it(`fixture file name matches loadName: ${labwarePath}`, () => {
284+
test(`fixture file name matches loadName: ${labwarePath}`, () => {
287285
expect(labwareDef.parameters.loadName).toEqual(
288286
path.basename(filename, '.json')
289287
)
290288
})
291289

292-
it(`namespace is "fixture": ${labwarePath}`, () => {
290+
test(`namespace is "fixture": ${labwarePath}`, () => {
293291
expect(labwareDef.namespace).toEqual('fixture')
294292
})
295293

shared-data/js/__tests__/labwareDefSchemaV3.test.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path'
22
import glob from 'glob'
3-
import { describe, expect, it, beforeAll, test } from 'vitest'
3+
import { describe, expect, it, test } from 'vitest'
44

55
import type { LabwareDefinition3 } from '../types'
66
import Ajv from 'ajv'
@@ -44,23 +44,22 @@ const checkGeometryDefinitions = (
4444
describe(`test additions to labware schema in v3`, () => {
4545
const labwarePaths = glob.sync(globPattern, { cwd: fixturesDir })
4646

47-
beforeAll(() => {
48-
// Make sure definitions path didn't break, which would give you false positives
47+
test("definition paths didn't break, which would give false positives", () => {
4948
expect(labwarePaths.length).toBeGreaterThan(0)
5049
})
5150

52-
labwarePaths.forEach(labwarePath => {
51+
describe.each(labwarePaths)('%s', labwarePath => {
5352
const filename = path.parse(labwarePath).base
5453
const fullLabwarePath = path.join(fixturesDir, labwarePath)
5554
const labwareDef = require(fullLabwarePath) as LabwareDefinition3
5655

57-
checkGeometryDefinitions(labwareDef, labwarePath)
58-
5956
it(`${filename} validates against schema`, () => {
6057
const valid = validate(labwareDef)
6158
const validationErrors = validate.errors
6259
expect(validationErrors).toBe(null)
6360
expect(valid).toBe(true)
6461
})
62+
63+
checkGeometryDefinitions(labwareDef, labwarePath)
6564
})
6665
})

0 commit comments

Comments
 (0)