-
Notifications
You must be signed in to change notification settings - Fork 948
Expand file tree
/
Copy pathfindLibraryName.test.ts
More file actions
113 lines (97 loc) · 2.77 KB
/
Copy pathfindLibraryName.test.ts
File metadata and controls
113 lines (97 loc) · 2.77 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
107
108
109
110
111
112
113
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import {findLibraryName} from '../findLibraryName';
import * as mocks from '../__fixtures__/android';
jest.mock('path');
jest.mock('fs');
const fs = require('fs');
const buildGradleWithSingleQuotes = `
apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
react {
libraryName = 'justalibrary'
}
`;
const buildGradleKts = `
apply(id = "com.android.application")
apply(id = "com.facebook.react")
react {
libraryName.set("justalibrary")
}
`;
const packageJsonWithCodegenConfig = `
{
"name": "my-awesome-library",
"version": "0.0.1",
"codegenConfig": {
"name": "my-awesome-library"
}
}
`;
const packageJsonWithoutCodegenConfig = `
{
"name": "my-awesome-library",
"version": "0.0.1"
}
`;
describe('android::findLibraryName', () => {
beforeAll(() => {
fs.__setMockFilesystem({
empty: {},
valid: {
android: mocks.valid,
singlequotes: {
'build.gradle': buildGradleWithSingleQuotes,
},
gradlekts: {
'build.gradle.kts': buildGradleKts,
},
withcodegenconfig: {
'package.json': packageJsonWithCodegenConfig,
android: {
'build.gradle': buildGradleWithSingleQuotes,
},
},
withoutcodegenconfig: {
'package.json': packageJsonWithoutCodegenConfig,
android: {
'build.gradle': buildGradleWithSingleQuotes,
},
},
},
});
});
it('returns the library name if declared in the build.gradle file', () => {
expect(findLibraryName('/', '/valid/android')).toBe('justalibrary');
});
it('returns the library name if declared with single quotes in the build.gradle file', () => {
expect(findLibraryName('/', '/valid/singlequotes')).toBe('justalibrary');
});
it('returns the library name if declared with inside a build.gradle.kts file', () => {
expect(findLibraryName('/', '/valid/gradlekts')).toBe('justalibrary');
});
it('returns the library name if defined inside codegenConfig', () => {
expect(
findLibraryName(
'/valid/withcodegenconfig',
'/valid/withcodegenconfig/android',
),
).toBe('my-awesome-library');
});
it('falls back to reading from build.gradle when codegenConfig is not there', () => {
expect(
findLibraryName(
'/valid/withoutcodegenconfig',
'/valid/withoutcodegenconfig/android',
),
).toBe('justalibrary');
});
it('returns null if there is no build.gradle file', () => {
expect(findLibraryName('/', '/empty')).toBeUndefined();
});
});