Skip to content

Commit 913ec72

Browse files
committed
test: stabilize runtime and plugin test workflow
1 parent 0a2a15a commit 913ec72

6 files changed

Lines changed: 81 additions & 27 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ jobs:
143143

144144
- run: bun install
145145

146-
- name: Start bundler
147-
run: bun start &
148-
working-directory: apps/example
149-
150146
- uses: actions/cache@v4
151147
with:
152148
path: packages/react-native-device-activity/ios/TestHarness/Pods
@@ -174,5 +170,5 @@ jobs:
174170
- run: pod install
175171
working-directory: packages/react-native-device-activity/ios/TestHarness
176172

177-
- run: xcodebuild test -workspace reactnativedeviceactivityexample.xcworkspace -scheme Tests -destination "platform=iOS Simulator,OS=latest,name=iPhone 17" CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO
173+
- run: xcodebuild test -workspace reactnativedeviceactivityexample.xcworkspace -scheme Tests -destination "platform=iOS Simulator,OS=latest,name=iPhone 17"
178174
working-directory: packages/react-native-device-activity/ios/TestHarness

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
"format:check": "node ./node_modules/prettier/bin/prettier.cjs --check .",
99
"format:version": "node ./node_modules/prettier/bin/prettier.cjs --version && node -e \"console.log(require('./node_modules/prettier/package.json').version)\"",
1010
"lint": "eslint .",
11+
"test": "cd packages/react-native-device-activity && bun run test",
1112
"swiftlint": "[ -x packages/react-native-device-activity/ios/TestHarness/Pods/SwiftLint/swiftlint ] || (echo 'SwiftLint pod binary missing. Run: cd packages/react-native-device-activity/ios/TestHarness && pod install' && exit 1); packages/react-native-device-activity/ios/TestHarness/Pods/SwiftLint/swiftlint lint --strict --config .swiftlint.yml",
12-
"pre-push": "bun run typecheck && bun run lint && bun run swiftlint",
13+
"pre-push": "bun run typecheck && bun run lint && bun run test && bun run swiftlint",
1314
"typecheck": "cd packages/react-native-device-activity && bun run typecheck && cd ../../apps/example && bun run typecheck",
1415
"prepare": "husky",
1516
"nail-workspace-dependency-versions": "bun run scripts/nail-workspace-dependency-versions.ts"

packages/react-native-device-activity/ios/Tests/IsShieldActiveTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import FamilyControls
88
import ManagedSettings
99
import Testing
1010

11+
// NOTE: These assertions fail on simulator when xcodebuild is run with
12+
// CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO.
1113
@Suite(.serialized) struct IsShieldActiveTests {
1214

1315
@Test func shieldIsNotActive() async throws {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
testEnvironment: "node",
3+
clearMocks: true,
4+
roots: ["<rootDir>/src"],
5+
testRegex: ".*\\.test\\.ts$",
6+
transform: {
7+
"^.+\\.[jt]sx?$": [
8+
"babel-jest",
9+
{
10+
configFile: require.resolve("expo-module-scripts/babel.config.cli.js"),
11+
},
12+
],
13+
},
14+
};

packages/react-native-device-activity/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"clean": "expo-module clean",
1010
"lint": "expo-module lint",
1111
"typecheck": "tsc --noEmit",
12-
"test": "expo-module test",
12+
"test": "bun run test:runtime && bun run test:plugin",
13+
"test:runtime": "expo-module test --config ./jest.runtime.config.js",
1314
"test:plugin": "expo-module test plugin",
1415
"prepublishOnly": "expo-module prepublishOnly && tsc && cp ../../README.md ./README.md",
1516
"expo-module": "expo-module",
Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,64 @@
1-
// todo: skipping for now
2-
3-
describe("test", () => {
4-
test("Should call stopMonitoring", () => {
5-
const mockStopMonitoring = jest.fn();
6-
jest.mock("./ReactNativeDeviceActivityModule", () => ({
7-
stopMonitoring: mockStopMonitoring,
8-
}));
9-
const { stopMonitoring } = require("./");
10-
stopMonitoring();
11-
expect(mockStopMonitoring).toHaveBeenCalled();
1+
const mockNativeModule = {
2+
stopMonitoring: jest.fn(),
3+
startMonitoring: jest.fn(),
4+
};
5+
6+
jest.mock("react-native", () => ({
7+
Platform: {
8+
OS: "ios",
9+
select: (options: Record<string, unknown>) =>
10+
options.ios ?? options.default,
11+
},
12+
}));
13+
14+
jest.mock("expo-modules-core", () => {
15+
class MockEventEmitter {
16+
addListener() {
17+
return { remove: jest.fn() };
18+
}
19+
20+
removeAllListeners() {}
21+
}
22+
23+
return {
24+
EventEmitter: MockEventEmitter,
25+
EventSubscription: class {},
26+
};
27+
});
28+
29+
jest.mock("./ReactNativeDeviceActivityModule", () => ({
30+
__esModule: true,
31+
default: mockNativeModule,
32+
}));
33+
34+
describe("index runtime wrapper", () => {
35+
beforeEach(() => {
36+
jest.clearAllMocks();
37+
jest.resetModules();
1238
});
1339

14-
test("Should call startMonitoring", () => {
15-
jest.resetAllMocks();
16-
const mockStartMonitoring = jest.fn();
17-
jest.mock("./ReactNativeDeviceActivityModule", () => ({
18-
startMonitoring: mockStartMonitoring,
19-
}));
20-
const { startMonitoring } = require("./");
21-
startMonitoring("test", {}, []);
22-
expect(mockStartMonitoring).toHaveBeenCalled();
40+
test("delegates stopMonitoring to native module", () => {
41+
const { stopMonitoring } = require("./index");
42+
const activities = ["activity-a"];
43+
44+
stopMonitoring(activities);
45+
46+
expect(mockNativeModule.stopMonitoring).toHaveBeenCalledWith(activities);
47+
});
48+
49+
test("delegates startMonitoring to native module", async () => {
50+
mockNativeModule.startMonitoring.mockResolvedValueOnce(undefined);
51+
const { startMonitoring } = require("./index");
52+
53+
await startMonitoring(
54+
"activity-a",
55+
{
56+
intervalStart: { hour: 0, minute: 0 },
57+
intervalEnd: { hour: 23, minute: 59 },
58+
},
59+
[],
60+
);
61+
62+
expect(mockNativeModule.startMonitoring).toHaveBeenCalled();
2363
});
2464
});

0 commit comments

Comments
 (0)