Skip to content

Commit 234a616

Browse files
committed
add tests
1 parent 508cfb7 commit 234a616

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

scripts/configure.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function mergeConfig(lhs, rhs) {
113113
* @param {string} configPath
114114
* @returns {boolean}
115115
*/
116-
function shouldUpdateReactNativeConfig(configPath, fs = nodefs) {
116+
export function shouldUpdateReactNativeConfig(configPath, fs = nodefs) {
117117
if (!fs.existsSync(configPath)) {
118118
return true;
119119
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { ok } from "node:assert/strict";
2+
import { afterEach, describe, it } from "node:test";
3+
import { shouldUpdateReactNativeConfig as shouldUpdateReactNativeConfigActual } from "../../scripts/configure.mjs";
4+
import { fs, setMockFiles } from "../fs.mock.js";
5+
6+
describe("shouldUpdateReactNativeConfig()", () => {
7+
const rnConfigFile = "react-native.config.js";
8+
9+
const shouldUpdateReactNativeConfig = () =>
10+
shouldUpdateReactNativeConfigActual(rnConfigFile, fs);
11+
12+
afterEach(() => setMockFiles());
13+
14+
it("returns true if `react-native.config.js` does not exist", () => {
15+
ok(shouldUpdateReactNativeConfig());
16+
});
17+
18+
it("returns true if `react-native.config.js` is not configured", () => {
19+
setMockFiles({ [rnConfigFile]: "module.exports = {};" });
20+
21+
ok(shouldUpdateReactNativeConfig());
22+
});
23+
24+
it("returns true if `react-native-test-app` is mentioned but not used", () => {
25+
setMockFiles({
26+
[rnConfigFile]: `// TODO: Use 'react-native-test-app'
27+
module.exports = {};
28+
`,
29+
});
30+
31+
ok(shouldUpdateReactNativeConfig());
32+
});
33+
34+
it("returns false if `react-native-test-app` is configured", () => {
35+
setMockFiles({
36+
[rnConfigFile]: `const { configureProjects } = require("react-native-test-app");
37+
module.exports = {
38+
project: configureProjects({
39+
android: {
40+
sourceDir: "android",
41+
},
42+
ios: {
43+
sourceDir: "ios",
44+
},
45+
}),
46+
dependencies: {
47+
MyPackage: {
48+
root: require("node:path").dirname(__dirname),
49+
},
50+
},
51+
};
52+
`,
53+
});
54+
55+
ok(!shouldUpdateReactNativeConfig());
56+
});
57+
});

0 commit comments

Comments
 (0)