|
| 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