/
once-per-template.test.ts
50 lines (44 loc) · 1.76 KB
/
once-per-template.test.ts
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
import { describe, it, expect, jest } from '@jest/globals';
import { filterTemplates, parseCommand } from './once-per-template';
import type { Templates } from './once-per-template';
jest.mock('../code/lib/cli/src/repro-templates', () => () => ({}));
const mockOptions = { foo: { type: 'string', values: ['bar', 'baz'] } };
jest.mock('./sandbox', () => ({ options: mockOptions }));
describe('parseCommand', () => {
it('grabs the script name and gets its options', async () => {
expect(await parseCommand(`yarn sandbox --foo bar`)).toEqual({
scriptName: 'sandbox',
command: 'yarn sandbox',
options: mockOptions,
values: { foo: 'bar' },
});
});
});
describe('filterTemplates', () => {
const templates: Templates = {
first: {
name: 'First',
script: 'first',
cadence: ['ci', 'daily'],
skipScripts: ['sandbox'],
},
second: {
name: 'Second',
script: 'second',
cadence: ['daily'],
},
};
it('filters only templates on the right cadence', () => {
expect(filterTemplates(templates, 'ci', 'smoketest')).toEqual({ first: templates.first });
expect(filterTemplates(templates, 'daily', 'smoketest')).toEqual(templates);
});
it('filters templates that do not skip the script', () => {
expect(filterTemplates(templates, 'daily', 'sandbox')).toEqual({ second: templates.second });
expect(filterTemplates(templates, 'daily', 'smoketest')).toEqual(templates);
});
// TODO: test for this, I don't really want to mess with circle env vars duing a test
// it('filters by CI concurrency', () => {
// expect(filterTemplates(templates, 'daily', 'sandbox')).toEqual({ second: templates.second });
// expect(filterTemplates(templates, 'daily', 'smoketest')).toEqual(templates);
// });
});