Repository navigation
Expand file tree
/
Copy pathspecNativeParityFindSingleMatch.test.ts
More file actions
53 lines (40 loc) · 1.79 KB
/
Copy pathspecNativeParityFindSingleMatch.test.ts
File metadata and controls
53 lines (40 loc) · 1.79 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
import { afterEach, beforeEach, describe, expect, it } from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import { findSingleMatch } from './specNativeParityHelper';
const HEADER = /^RNFB.*TurboModules\.h$/;
describe('specNativeParityHelper findSingleMatch', function () {
let rootDir: string;
function touch(relativePath: string): string {
const fullPath = path.join(rootDir, relativePath);
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
fs.writeFileSync(fullPath, '');
return fullPath;
}
beforeEach(function () {
rootDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rnfb-find-single-match-'));
});
afterEach(function () {
fs.rmSync(rootDir, { recursive: true, force: true });
});
it('returns the single real match', function () {
const generated = touch('generated/RNFBAppTurboModules/RNFBAppTurboModules.h');
expect(findSingleMatch(rootDir, HEADER, 'header')).toBe(generated);
});
it('ignores look-alike files under HostStubs directories', function () {
const generated = touch('generated/RNFBAppTurboModules/RNFBAppTurboModules.h');
touch('RNFBAppUnitTests/HostStubs/RNFBAppTurboModules.h');
expect(findSingleMatch(rootDir, HEADER, 'header')).toBe(generated);
});
it('still throws when two real matches exist', function () {
touch('generated/RNFBAppTurboModules/RNFBAppTurboModules.h');
touch('other/RNFBAppTurboModules.h');
touch('RNFBAppUnitTests/HostStubs/RNFBAppTurboModules.h');
expect(() => findSingleMatch(rootDir, HEADER, 'header')).toThrow(/found 2/);
});
it('throws when the only match is under HostStubs', function () {
touch('RNFBAppUnitTests/HostStubs/RNFBAppTurboModules.h');
expect(() => findSingleMatch(rootDir, HEADER, 'header')).toThrow(/found 0/);
});
});