-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpubspecTestRunner.test.ts
More file actions
68 lines (52 loc) · 2.08 KB
/
Copy pathpubspecTestRunner.test.ts
File metadata and controls
68 lines (52 loc) · 2.08 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
import fs from 'fs/promises';
import os from 'os';
import path from 'path';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import {
spliceTestRunnerDevDependency,
withTemporaryTestRunnerDep,
} from '../../src/core/pubspecTestRunner.js';
const SAMPLE_PUBSPEC = `name: demo
dev_dependencies:
flutter_test:
sdk: flutter
`;
describe('pubspecTestRunner', () => {
let tmpDir: string;
beforeEach(async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'ensemble-pubspec-test-runner-'));
});
afterEach(async () => {
await fs.rm(tmpDir, { recursive: true, force: true });
});
it('splices test runner under dev_dependencies', () => {
const updated = spliceTestRunnerDevDependency(SAMPLE_PUBSPEC);
expect(updated).toContain('ensemble_test_runner:');
expect(updated).toContain('ref: support-test-cases');
});
it('restores pubspec after callback', async () => {
await fs.writeFile(path.join(tmpDir, 'pubspec.yaml'), SAMPLE_PUBSPEC, 'utf8');
await withTemporaryTestRunnerDep(tmpDir, async () => undefined);
expect(await fs.readFile(path.join(tmpDir, 'pubspec.yaml'), 'utf8')).toBe(SAMPLE_PUBSPEC);
});
it('restores pubspec when callback throws', async () => {
await fs.writeFile(path.join(tmpDir, 'pubspec.yaml'), SAMPLE_PUBSPEC, 'utf8');
await expect(
withTemporaryTestRunnerDep(tmpDir, async () => {
throw new Error('test failed');
})
).rejects.toThrow(/test failed/i);
expect(await fs.readFile(path.join(tmpDir, 'pubspec.yaml'), 'utf8')).toBe(SAMPLE_PUBSPEC);
});
it('skips splice when ensemble_test_runner is already in pubspec', async () => {
const pubspec = `${SAMPLE_PUBSPEC} ensemble_test_runner:
git:
url: https://github.com/EnsembleUI/ensemble.git
ref: support-test-cases
path: packages/ensemble_test_runner
`;
await fs.writeFile(path.join(tmpDir, 'pubspec.yaml'), pubspec, 'utf8');
await withTemporaryTestRunnerDep(tmpDir, async () => undefined);
expect(await fs.readFile(path.join(tmpDir, 'pubspec.yaml'), 'utf8')).toBe(pubspec);
});
});