@ng-native/template 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +8 -0
- package/README.md +12 -0
- package/gitignore +4 -0
- package/metro.config.js +4 -1
- package/package.json +8 -8
- package/src/app/app.device.ts +8 -0
- package/src/main.ts +36 -19
- package/vitest.config.mts +12 -3
package/AGENTS.md
CHANGED
|
@@ -18,6 +18,9 @@ npm start # Metro; press i or a for a simulator, or scan the QR code w
|
|
|
18
18
|
npm run ios # the iOS simulator
|
|
19
19
|
npm run android # the Android emulator
|
|
20
20
|
npm test # Vitest, in Node against a fake native layer: no simulator needed
|
|
21
|
+
npx vitest --project ios # tests in src/**/*.device.ts, inside the running app on a
|
|
22
|
+
# simulator, which it builds and starts, with its own Metro
|
|
23
|
+
npx vitest --project android # the same on an Android emulator
|
|
21
24
|
npm run typecheck
|
|
22
25
|
```
|
|
23
26
|
|
|
@@ -85,6 +88,11 @@ change; both are fast.
|
|
|
85
88
|
`userEvent.setup().press(...)` or `.type(...)`, all from `@ng-native/testing`. Tests run in Node
|
|
86
89
|
with no simulator, so write one alongside a change.
|
|
87
90
|
|
|
91
|
+
A file under `src` ending in `.device.ts` runs inside the running app instead, on real native views, from
|
|
92
|
+
`@ng-native/testing/device`: `npx vitest --project` with an OS the app's `vitest.config.mts` has a
|
|
93
|
+
project for (`ios`, `android` or `macos`), from the app's directory. The first run builds the app,
|
|
94
|
+
which needs Xcode or the Android SDK, and takes some minutes; later runs take seconds.
|
|
95
|
+
|
|
88
96
|
A service that depends on the platform injects `OS` and `OS_VERSION` from `@ng-native/device`
|
|
89
97
|
rather than importing `Platform` from `react-native`, which a test cannot load. A test provides
|
|
90
98
|
the values it wants: `{ provide: OS, useValue: 'android' }`.
|
package/README.md
CHANGED
|
@@ -14,6 +14,18 @@ npm run typecheck
|
|
|
14
14
|
release build or a native module Expo Go does not include needs a development build
|
|
15
15
|
(`npx expo run:ios`).
|
|
16
16
|
|
|
17
|
+
To run tests inside the app, on real native views, run the `ios` or `android` Vitest project,
|
|
18
|
+
which starts Metro, builds the app and opens it on a simulator or emulator itself
|
|
19
|
+
(`src/app/app.device.ts` is the example):
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npx vitest --project ios
|
|
23
|
+
npx vitest --project android
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The first run builds a development build, which takes some minutes and needs Xcode for iOS or the
|
|
27
|
+
Android SDK for Android; later runs reuse it. `npm test` runs the Node project, `node`, alone.
|
|
28
|
+
|
|
17
29
|
The app targets iOS and Android, so `npm run web`, which `create-expo-app` suggests as it finishes,
|
|
18
30
|
only says so and exits. Angular Native components can also render in a browser, set up as
|
|
19
31
|
https://ng-native.com/packages/web#beside-a-native-app describes.
|
package/gitignore
CHANGED
|
@@ -41,3 +41,7 @@ yarn-error.*
|
|
|
41
41
|
|
|
42
42
|
# Generated by @ng-native/tailwind's withTailwind, rebuilt on every Metro start
|
|
43
43
|
.angular-native/
|
|
44
|
+
|
|
45
|
+
# Written beside a reference screenshot when a device test's capture differs from it
|
|
46
|
+
**/__screenshots__/**/*-actual.png
|
|
47
|
+
**/__screenshots__/**/*-diff.png
|
package/metro.config.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
const { getDefaultConfig } = require('expo/metro-config');
|
|
2
2
|
const { withAngularNative } = require('@ng-native/metro/config.cjs');
|
|
3
|
+
const { withDeviceTests } = require('@ng-native/testing/device/metro');
|
|
3
4
|
|
|
4
5
|
// Registers the transformer that compiles Angular ahead of time, compiles each component's CSS
|
|
5
6
|
// into the sheet the engine reads, and adds the polyfills Angular needs before `@angular/core`
|
|
6
7
|
// is first evaluated. No options: the framework packages are ordinary dependencies here.
|
|
7
|
-
|
|
8
|
+
// `withDeviceTests` does nothing until Metro starts with EXPO_PUBLIC_DEVICE_TESTS set, for the
|
|
9
|
+
// tests that run inside the app.
|
|
10
|
+
module.exports = withDeviceTests(withAngularNative(getDefaultConfig(__dirname)));
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-native/template",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "An Angular app rendering real native views. Use with create-expo-app --template.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/main.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@ng-native/components": "0.
|
|
9
|
-
"@ng-native/device": "0.
|
|
10
|
-
"@ng-native/fabric": "0.
|
|
11
|
-
"@ng-native/metro": "0.
|
|
12
|
-
"@ng-native/platform": "0.
|
|
8
|
+
"@ng-native/components": "0.26.0",
|
|
9
|
+
"@ng-native/device": "0.26.0",
|
|
10
|
+
"@ng-native/fabric": "0.26.0",
|
|
11
|
+
"@ng-native/metro": "0.26.0",
|
|
12
|
+
"@ng-native/platform": "0.26.0",
|
|
13
13
|
"@angular/common": "^22.0.0",
|
|
14
14
|
"@angular/core": "^22.0.0",
|
|
15
15
|
"expo": "~58.0.16",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@angular/compiler-cli": "^22.0.0",
|
|
24
24
|
"@babel/core": "^7.29.7",
|
|
25
|
-
"@ng-native/testing": "0.
|
|
25
|
+
"@ng-native/testing": "0.26.0",
|
|
26
26
|
"@types/react": "~19.3.0",
|
|
27
27
|
"typescript": "~6.0.3",
|
|
28
28
|
"vitest": "^5.0.0"
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
"ios": "expo start --ios",
|
|
39
39
|
"web": "node -e \"console.error('This app targets iOS and Android: use npm start, npm run ios or npm run android. To render it in a browser, see https://ng-native.com/packages/web#beside-a-native-app'); process.exit(1)\"",
|
|
40
40
|
"typecheck": "node metro.config.js && ngc -p tsconfig.json --noEmit",
|
|
41
|
-
"test": "vitest run"
|
|
41
|
+
"test": "vitest run --project node"
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
// Runs inside the app, on real native views: `npx vitest --project ios` or `--project android`.
|
|
5
|
+
// Render a component with `render` and `screen` from `@ng-native/testing/device`.
|
|
6
|
+
it('runs on a phone', () => {
|
|
7
|
+
expect(['ios', 'android']).toContain(Platform.OS);
|
|
8
|
+
});
|
package/src/main.ts
CHANGED
|
@@ -10,24 +10,41 @@ import { App } from './app/app.ts';
|
|
|
10
10
|
|
|
11
11
|
registerPlatformComponents(Platform.OS);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
/** What `mount` takes, for the app and for the tests that run inside it. */
|
|
14
|
+
const mountOptions = () => ({
|
|
15
|
+
// Colours, as the integers the platform wants.
|
|
16
|
+
processColor,
|
|
17
|
+
// What `@media` resolves against. Without it every media query is false and a responsive
|
|
18
|
+
// layout renders as its smallest case.
|
|
19
|
+
conditions: currentConditions(),
|
|
20
|
+
// Values only the device knows - the hairline width, which is a third of a point on a 3x
|
|
21
|
+
// screen. Without it `1px` is what you get, and that is a visibly fat divider.
|
|
22
|
+
tokens: deviceTokens(),
|
|
23
|
+
// Turns a `require('./x.png')` into something native can load. Without it images are blank.
|
|
24
|
+
resolveAssetSource: (value: unknown) => Image.resolveAssetSource(value as never),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (process.env.EXPO_PUBLIC_DEVICE_TESTS) {
|
|
28
|
+
// Metro was started for `vitest --project ios` or `android`: the test host, not the app.
|
|
29
|
+
const { startDeviceTests } =
|
|
30
|
+
require('@ng-native/testing/device/host') as typeof import('@ng-native/testing/device/host');
|
|
31
|
+
startDeviceTests({
|
|
32
|
+
mount: mountOptions,
|
|
33
|
+
// The host follows rotation, the theme and reduced motion as the app does.
|
|
34
|
+
onMount: (app) => {
|
|
35
|
+
const stopWatching = watchConditions(app.engine);
|
|
36
|
+
app.applicationRef.onDestroy(stopWatching);
|
|
37
|
+
},
|
|
25
38
|
});
|
|
39
|
+
} else {
|
|
40
|
+
AppRegistry.registerRunnable('main', ({ rootTag }) => {
|
|
41
|
+
const app = mount(Number(rootTag), App, getFabricUIManager(), mountOptions());
|
|
26
42
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
43
|
+
// Re-resolves the conditions when the device rotates or the theme changes. A rotation dirties
|
|
44
|
+
// no component and no binding, so without this nothing re-renders and `dark:` stops following
|
|
45
|
+
// the system switch. It stops with the app, which Android destroys when it recreates the
|
|
46
|
+
// activity, so the app mounted in its place is the only one still watching.
|
|
47
|
+
const stopWatching = watchConditions(app.engine);
|
|
48
|
+
app.applicationRef.onDestroy(stopWatching);
|
|
49
|
+
});
|
|
50
|
+
}
|
package/vitest.config.mts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { ngNative } from '@ng-native/testing/vitest';
|
|
2
|
+
import { deviceTests } from '@ng-native/testing/device/vitest';
|
|
2
3
|
import { defineConfig } from 'vitest/config';
|
|
3
4
|
|
|
4
|
-
//
|
|
5
|
-
// a fake of the native side: no simulator, no device.
|
|
5
|
+
// Three projects. `node` compiles Angular for the tests the way Metro compiles it for the app and
|
|
6
|
+
// runs them in Node against a fake of the native side: no simulator, no device. `ios` and
|
|
7
|
+
// `android` run the `*.device.ts` files inside the running app on a simulator or emulator,
|
|
8
|
+
// starting Metro, the build and the app themselves. `npm test` runs `node` alone.
|
|
6
9
|
export default defineConfig({
|
|
7
|
-
|
|
10
|
+
test: {
|
|
11
|
+
projects: [
|
|
12
|
+
{ plugins: [ngNative()], test: { name: 'node' } },
|
|
13
|
+
{ plugins: [deviceTests({ platform: 'ios' })] },
|
|
14
|
+
{ plugins: [deviceTests({ platform: 'android' })] },
|
|
15
|
+
],
|
|
16
|
+
},
|
|
8
17
|
});
|