-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathmobile-test-groups.test.js
More file actions
106 lines (92 loc) · 4.2 KB
/
Copy pathmobile-test-groups.test.js
File metadata and controls
106 lines (92 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'use strict'
const test = require('node:test')
const assert = require('node:assert/strict')
const fs = require('node:fs')
const path = require('node:path')
const { validateTestGroups, platformNames } = require('../lib/validate-test-groups.js')
const groups = require('../../test/mobile/test-groups.json')
const integrationAutoPath = path.resolve(__dirname, '../../test/mobile/integration.auto.cjs')
function generatedRunners() {
const content = fs.readFileSync(integrationAutoPath, 'utf8')
return Array.from(content.matchAll(/^async function (run[A-Za-z0-9_]+)\s*\(/gm), (m) => m[1])
}
test('the committed test-groups.json covers every generated runner', () => {
assert.deepEqual(validateTestGroups(groups, generatedRunners()), [])
})
test('deferred runners are declared, not silently absent', () => {
// pi05 mobile coverage is deferred pending a project-owned CDN mirror, and
// pi05.test.js is gated on-device by `_skipMobilePi05`. Recording it here is
// what keeps "not scheduled" distinguishable from "forgotten".
assert.deepEqual(groups.deferred, ['runPi05Test'])
for (const platform of platformNames(groups)) {
const scheduled = Object.values(groups[platform]).flat()
assert.ok(
!scheduled.includes('runPi05Test'),
`runPi05Test must not be scheduled on ${platform}`
)
}
})
test('"deferred" is a top-level key, never a platform', () => {
// The Device Farm composites read only `.<platform>`, so a `deferred` key
// nested inside ios/android would be scheduled as a real shard.
assert.ok(!platformNames(groups).includes('deferred'))
assert.deepEqual(platformNames(groups).sort(), ['android', 'ios'])
})
test('a "deferred" key nested inside a platform is reported', () => {
// The assertion above only covers the committed file's shape. This covers the
// hazard itself: nested under a platform, `deferred` is just another array of
// runner names, so every other rule is satisfied and the file would otherwise
// validate clean — while upload-to-devicefarm schedules it as a real shard.
const nested = {
ios: { smolvla: ['runAddonTest'], deferred: ['runPi05Test'] },
android: { smolvla: ['runAddonTest'], deferred: ['runPi05Test'] }
}
const problems = validateTestGroups(nested, ['runAddonTest', 'runPi05Test'])
assert.equal(problems.length, 2, 'exactly one problem per platform')
for (const platform of ['ios', 'android']) {
const reported = problems.some(
(p) => p.startsWith(`[${platform}]`) && p.includes('nested inside the platform map')
)
assert.ok(reported, `${platform} must report the nested "deferred" key`)
}
})
test('an unassigned runner is reported', () => {
const problems = validateTestGroups(groups, [...generatedRunners(), 'runBrandNewTest'])
assert.equal(problems.length, platformNames(groups).length)
assert.ok(problems.every((p) => p.includes('runBrandNewTest')))
})
test('a typo in a group is reported', () => {
const typo = {
ios: { smolvla: ['runAddonTest', 'runTypoTest'] },
deferred: []
}
const problems = validateTestGroups(typo, ['runAddonTest'])
assert.ok(problems.some((p) => p.includes('runTypoTest') && p.includes('do not exist')))
})
test('a stale deferred entry is reported', () => {
const stale = {
ios: { smolvla: ['runAddonTest'] },
deferred: ['runRemovedTest']
}
const problems = validateTestGroups(stale, ['runAddonTest'])
assert.ok(problems.some((p) => p.includes('runRemovedTest') && p.includes('do not exist')))
})
test('a runner that is both scheduled and deferred is reported', () => {
const contradictory = {
ios: { smolvla: ['runAddonTest'] },
deferred: ['runAddonTest']
}
const problems = validateTestGroups(contradictory, ['runAddonTest'])
assert.ok(problems.some((p) => p.includes('both scheduled and listed')))
})
test('metadata keys that are not platform maps are ignored', () => {
// OCR ships a top-level `perf_report_filter` string; the shape must tolerate
// sibling metadata without treating it as a platform.
const withMetadata = {
ios: { smolvla: ['runAddonTest'] },
perf_report_filter: 'something|else',
deferred: []
}
assert.deepEqual(platformNames(withMetadata), ['ios'])
assert.deepEqual(validateTestGroups(withMetadata, ['runAddonTest']), [])
})