@ng-native/schematics 0.25.0 → 0.26.1
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/application/index.cjs +1 -4
- package/builders/vitest.json +1 -1
- package/files/AGENTS.md +8 -0
- package/files/desktop/AGENTS.md +7 -2
- package/files/desktop/src/app/app.device.ts +5 -4
- package/files/desktop/src/main.ts +8 -1
- package/files/desktop/vitest.config.mts +2 -2
- package/files/metro.config.js +4 -1
- package/files/src/app/app.device.ts +8 -0
- package/files/src/main.ts +36 -19
- package/files/vitest.config.mts +12 -3
- package/migrations.json +1 -1
- package/native-app.cjs +10 -11
- package/package.json +2 -2
- package/files/desktop/metro.config.js +0 -10
package/application/index.cjs
CHANGED
|
@@ -44,7 +44,7 @@ function targets(root, name, lint = false, desktopOnly = false) {
|
|
|
44
44
|
: { 'run-ios': expo('run:ios'), 'run-android': expo('run:android') }),
|
|
45
45
|
test: {
|
|
46
46
|
builder: '@ng-native/schematics:vitest',
|
|
47
|
-
options:
|
|
47
|
+
options: { project: desktopOnly ? native.DESKTOP_TEST_PROJECT : native.TEST_PROJECT },
|
|
48
48
|
},
|
|
49
49
|
typecheck: { builder: '@ng-native/schematics:typecheck', options: {} },
|
|
50
50
|
// With `--linter=eslint`, angular-eslint's builder, which `ng lint` runs, with the project's
|
|
@@ -142,9 +142,6 @@ function writeFiles(tree, root, name, bundleIdentifier, lint, desktopOnly) {
|
|
|
142
142
|
for (const file of native.SOURCE_FILES) {
|
|
143
143
|
tree.create(path.join(root, file), native.sourceFile(file, desktopOnly));
|
|
144
144
|
}
|
|
145
|
-
for (const file of desktopOnly ? native.DESKTOP_ONLY_FILES : []) {
|
|
146
|
-
tree.create(path.join(root, file), native.sourceFile(file, true));
|
|
147
|
-
}
|
|
148
145
|
const platforms = desktopOnly ? ['macos'] : undefined;
|
|
149
146
|
tree.create(path.join(root, 'app.json'), native.appJson(name, bundleIdentifier, platforms));
|
|
150
147
|
tree.create(
|
package/builders/vitest.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"project": {
|
|
17
17
|
"type": "string",
|
|
18
|
-
"description": "Only this Vitest project, by its name in vitest.config.mts. A
|
|
18
|
+
"description": "Only this Vitest project, by its name in vitest.config.mts. A generated app's test target runs node (node-macos in a desktop-only app), since its other projects open the app."
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
package/files/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/files/desktop/AGENTS.md
CHANGED
|
@@ -18,8 +18,8 @@ browser-only parts do not: there is no `NgOptimizedImage` (use `<image>`), and n
|
|
|
18
18
|
npm start # Metro, the dev server the app loads from
|
|
19
19
|
npm run macos # builds the desktop host (the first time) and opens the app from Metro
|
|
20
20
|
npm test # Vitest, in Node against a fake native layer: no app window needed
|
|
21
|
-
npx vitest --project macos # tests in src/**/*.device.ts, inside the running app
|
|
22
|
-
#
|
|
21
|
+
npx vitest --project macos # tests in src/**/*.device.ts, inside the running app, which it
|
|
22
|
+
# starts, with its own Metro
|
|
23
23
|
npm run typecheck
|
|
24
24
|
npm run package # the .app
|
|
25
25
|
npm run package -- --format dmg # a signed, notarised download; --format mas for the Mac App Store
|
|
@@ -89,6 +89,11 @@ change; both are fast.
|
|
|
89
89
|
`userEvent.setup().press(...)` or `.type(...)`, all from `@ng-native/testing`. Tests run in Node
|
|
90
90
|
with no simulator, so write one alongside a change.
|
|
91
91
|
|
|
92
|
+
A file under `src` ending in `.device.ts` runs inside the running app instead, on real native views, from
|
|
93
|
+
`@ng-native/testing/device`: `npx vitest --project` with an OS the app's `vitest.config.mts` has a
|
|
94
|
+
project for (`ios`, `android` or `macos`), from the app's directory. The first run builds the app,
|
|
95
|
+
which needs Xcode or the Android SDK, and takes some minutes; later runs take seconds.
|
|
96
|
+
|
|
92
97
|
A service that depends on the platform injects `OS` and `OS_VERSION` from `@ng-native/device`
|
|
93
98
|
rather than importing `Platform` from `react-native`, which a test cannot load. A test provides
|
|
94
99
|
the values it wants: `{ provide: OS, useValue: 'android' }`.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
2
|
import { expect, it } from 'vitest';
|
|
3
3
|
|
|
4
|
-
// Runs inside the app, on real
|
|
5
|
-
// with `render` and `screen` from
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
// Runs inside the app, on real native views: `npx vitest --project macos`, and `ios` or `android`
|
|
5
|
+
// once the app has those projects. Render a component with `render` and `screen` from
|
|
6
|
+
// `@ng-native/testing/device`.
|
|
7
|
+
it('runs inside the app', () => {
|
|
8
|
+
expect(['macos', 'ios', 'android']).toContain(Platform.OS);
|
|
8
9
|
});
|
|
@@ -28,7 +28,14 @@ if (process.env.EXPO_PUBLIC_DEVICE_TESTS) {
|
|
|
28
28
|
// Metro was started for `vitest --project macos`: the test host, not the app.
|
|
29
29
|
const { startDeviceTests } =
|
|
30
30
|
require('@ng-native/testing/device/host') as typeof import('@ng-native/testing/device/host');
|
|
31
|
-
startDeviceTests({
|
|
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
|
+
},
|
|
38
|
+
});
|
|
32
39
|
} else {
|
|
33
40
|
AppRegistry.registerRunnable('main', ({ rootTag }) => {
|
|
34
41
|
const app = mount(Number(rootTag), App, getFabricUIManager(), mountOptions());
|
|
@@ -4,8 +4,8 @@ import { defineConfig } from 'vitest/config';
|
|
|
4
4
|
|
|
5
5
|
// Two projects. `node-macos` compiles Angular for the tests the way Metro compiles it for the app
|
|
6
6
|
// and runs them in Node against a fake of the native side: no app window. `macos` runs the
|
|
7
|
-
// `*.device.ts` files inside the running app on this Mac,
|
|
8
|
-
//
|
|
7
|
+
// `*.device.ts` files inside the running app on this Mac, starting Metro and the app itself.
|
|
8
|
+
// `npm test` runs `node-macos` alone.
|
|
9
9
|
export default defineConfig({
|
|
10
10
|
test: {
|
|
11
11
|
projects: [
|
package/files/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)));
|
|
@@ -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/files/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/files/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
|
});
|
package/migrations.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json",
|
|
3
3
|
"schematics": {
|
|
4
4
|
"sync-app-versions": {
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.26.1",
|
|
6
6
|
"description": "Move the @ng-native packages each project's own package.json lists to the new version.",
|
|
7
7
|
"factory": "./migrations/run.cjs#sync-app-versions"
|
|
8
8
|
},
|
package/native-app.cjs
CHANGED
|
@@ -22,16 +22,16 @@ const SOURCE_FILES = [
|
|
|
22
22
|
'src/app/app.ts',
|
|
23
23
|
'src/main.ts',
|
|
24
24
|
'src/app/app.test.ts',
|
|
25
|
+
'src/app/app.device.ts',
|
|
25
26
|
'vitest.config.mts',
|
|
26
27
|
'metro.config.js',
|
|
27
28
|
'tsconfig.json',
|
|
28
29
|
];
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
* The desktop template's files that differ from the template's,
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* each, and the Metro config that keeps the in-app tests out of an ordinary bundle. Its `AGENTS.md`
|
|
32
|
+
* The desktop template's files that differ from the template's, which a desktop-only app takes
|
|
33
|
+
* from `files/desktop/`: its starter screen, the screen's Node test and in-app test, the entry file
|
|
34
|
+
* that starts the in-app tests, and the Vitest config with its macOS projects. Its `AGENTS.md`
|
|
35
35
|
* comes from there too, through `agentsFile`.
|
|
36
36
|
*/
|
|
37
37
|
const DESKTOP_SOURCE_FILES = [
|
|
@@ -40,16 +40,15 @@ const DESKTOP_SOURCE_FILES = [
|
|
|
40
40
|
'src/app/app.device.ts',
|
|
41
41
|
'src/main.ts',
|
|
42
42
|
'vitest.config.mts',
|
|
43
|
-
'metro.config.js',
|
|
44
43
|
];
|
|
45
44
|
|
|
46
|
-
/** The desktop template's files a desktop-only app has and a mobile one does not. */
|
|
47
|
-
const DESKTOP_ONLY_FILES = ['src/app/app.device.ts'];
|
|
48
|
-
|
|
49
45
|
/**
|
|
50
|
-
* The
|
|
51
|
-
*
|
|
46
|
+
* The template's Vitest project that runs in Node, which `ng test` runs alone: its `ios` and
|
|
47
|
+
* `android` projects build and open the app.
|
|
52
48
|
*/
|
|
49
|
+
const TEST_PROJECT = 'node';
|
|
50
|
+
|
|
51
|
+
/** The desktop template's, whose other project opens the app on the Mac. */
|
|
53
52
|
const DESKTOP_TEST_PROJECT = 'node-macos';
|
|
54
53
|
|
|
55
54
|
/**
|
|
@@ -98,7 +97,7 @@ module.exports = {
|
|
|
98
97
|
...shared,
|
|
99
98
|
SOURCE_FILES,
|
|
100
99
|
DESKTOP_SOURCE_FILES,
|
|
101
|
-
|
|
100
|
+
TEST_PROJECT,
|
|
102
101
|
DESKTOP_TEST_PROJECT,
|
|
103
102
|
sourceFile,
|
|
104
103
|
agentsFile,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-native/schematics",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"description": "ng add and ng generate for Angular Native: an Expo app in an Angular CLI workspace, with builders that run it.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@angular-devkit/architect": ">=0.2200.0 <0.2300.0",
|
|
52
52
|
"@angular-devkit/core": "^22.0.0",
|
|
53
53
|
"@angular-devkit/schematics": "^22.0.0",
|
|
54
|
-
"@ng-native/migrate": "0.
|
|
54
|
+
"@ng-native/migrate": "0.26.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@schematics/angular": "22.1.9"
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const { getDefaultConfig } = require('expo/metro-config');
|
|
2
|
-
const { withAngularNative } = require('@ng-native/metro/config.cjs');
|
|
3
|
-
const { withDeviceTests } = require('@ng-native/testing/device/metro');
|
|
4
|
-
|
|
5
|
-
// Registers the transformer that compiles Angular ahead of time, compiles each component's CSS
|
|
6
|
-
// into the sheet the engine reads, and adds the polyfills Angular needs before `@angular/core`
|
|
7
|
-
// is first evaluated. No options: the framework packages are ordinary dependencies here.
|
|
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)));
|