Skip to content

Commit

Permalink
fix(expo): fix expo detox test (#16779)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9423508)
  • Loading branch information
xiongemi authored and FrozenPandaz committed May 9, 2023
1 parent 5d983ef commit da912b2
Show file tree
Hide file tree
Showing 25 changed files with 484 additions and 47 deletions.
6 changes: 6 additions & 0 deletions docs/generated/packages/detox/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
},
"framework": {
"type": "string",
"description": "App framework to test",
"enum": ["react-native", "expo"],
"default": "react-native"
}
},
"required": [],
Expand Down
4 changes: 4 additions & 0 deletions docs/generated/packages/expo/executors/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"description": "Run build locally [experimental]",
"default": false
},
"output": {
"type": "string",
"description": "Output path for local build"
},
"wait": {
"type": "boolean",
"description": "Wait for build(s) to complete",
Expand Down
19 changes: 19 additions & 0 deletions packages/detox/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
"version": "16.0.0-beta.3",
"description": "Update .detoxrc.json and jest.config.json for detox 20",
"implementation": "./src/migrations/update-16-0-0/update-detoxrc-json"
},
"update-detoxrc-json-expo-16-1-4": {
"cli": "nx",
"version": "16.1.4-beta.0",
"description": "Update .detoxrc.json for expo",
"implementation": "./src/migrations/update-16-1-4/update-detoxrc-json-expo"
}
},
"packageJsonUpdates": {
Expand Down Expand Up @@ -222,6 +228,19 @@
"alwaysAddToPackageJson": false
}
}
},
"16.1.1": {
"version": "16.1.1-beta.0",
"packages": {
"detox": {
"version": "~20.8.0",
"alwaysAddToPackageJson": false
},
"@config-plugins/detox": {
"version": "~5.0.1",
"alwaysAddToPackageJson": false
}
}
}
}
}
2 changes: 1 addition & 1 deletion packages/detox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@nx/react": "file:../react"
},
"peerDependencies": {
"detox": "~20.7.0"
"detox": "~20.8.0"
},
"builders": "./executors.json",
"ng-update": {
Expand Down
12 changes: 6 additions & 6 deletions packages/detox/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ describe('detox application generator', () => {
'android.eas': {
binaryPath: '../../../my-dir/my-app/dist/MyDirMyApp.apk',
build:
'npx nx run my-dir-my-app:download --platform android --output=my-dir/my-app/dist/',
type: 'ios.app',
'npx nx run my-dir-my-app:download --platform android --output=../../../my-dir/my-app/dist/',
type: 'android.apk',
},
'android.local': {
binaryPath: '../../../my-dir/my-app/dist/MyDirMyApp.apk',
build:
'npx nx run my-dir-my-app:build --platform android --profile preview --wait --local --no-interactive --output=my-dir/my-app/dist/',
type: 'ios.app',
'npx nx run my-dir-my-app:build --platform android --profile preview --wait --local --no-interactive --output=../../../my-dir/my-app/dist/MyDirMyApp.apk',
type: 'android.apk',
},
'android.release': {
binaryPath:
Expand All @@ -371,13 +371,13 @@ describe('detox application generator', () => {
'ios.eas': {
binaryPath: '../../../my-dir/my-app/dist/MyDirMyApp.app',
build:
'npx nx run my-dir-my-app:download --platform ios --distribution simulator --output=my-dir/my-app/dist/',
'npx nx run my-dir-my-app:download --platform ios --distribution simulator --output=../../../my-dir/my-app/dist/',
type: 'ios.app',
},
'ios.local': {
binaryPath: '../../../my-dir/my-app/dist/MyDirMyApp.app',
build:
'npx nx run my-dir-my-app:build --platform ios --profile preview --wait --local --no-interactive --output=my-dir/my-app/dist/',
'npx nx run my-dir-my-app:build --platform ios --profile preview --wait --local --no-interactive --output=../../../my-dir/my-app/dist/MyDirMyApp.tar.gz',
type: 'ios.app',
},
'ios.release': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<% if (framework === 'expo') { %>
"ios.eas": {
"type": "ios.app",
"build": "<%= exec %> nx run <%= appFileName %>:download --platform ios --distribution simulator --output=<%= appRoot %>/dist/",
"build": "<%= exec %> nx run <%= appFileName %>:download --platform ios --distribution simulator --output=<%= offsetFromRoot %><%= appRoot %>/dist/",
"binaryPath": "<%= offsetFromRoot %><%= appRoot %>/dist/<%= appExpoName %>.app"
},
"ios.local": {
"type": "ios.app",
"build": "<%= exec %> nx run <%= appFileName %>:build --platform ios --profile preview --wait --local --no-interactive --output=<%= appRoot %>/dist/",
"build": "<%= exec %> nx run <%= appFileName %>:build --platform ios --profile preview --wait --local --no-interactive --output=<%= offsetFromRoot %><%= appRoot %>/dist/<%= appExpoName %>.tar.gz",
"binaryPath": "<%= offsetFromRoot %><%= appRoot %>/dist/<%= appExpoName %>.app"
},
<% } %>
Expand All @@ -43,13 +43,13 @@
},
<% if (framework === 'expo') { %>
"android.eas": {
"type": "ios.app",
"build": "<%= exec %> nx run <%= appFileName %>:download --platform android --output=<%= appRoot %>/dist/",
"type": "android.apk",
"build": "<%= exec %> nx run <%= appFileName %>:download --platform android --output=<%= offsetFromRoot %><%= appRoot %>/dist/",
"binaryPath": "<%= offsetFromRoot %><%= appRoot %>/dist/<%= appExpoName %>.apk"
},
"android.local": {
"type": "ios.app",
"build": "<%= exec %> nx run <%= appFileName %>:build --platform android --profile preview --wait --local --no-interactive --output=<%= appRoot %>/dist/",
"type": "android.apk",
"build": "<%= exec %> nx run <%= appFileName %>:build --platform android --profile preview --wait --local --no-interactive --output=<%= offsetFromRoot %><%= appRoot %>/dist/<%= appExpoName %>.apk",
"binaryPath": "<%= offsetFromRoot %><%= appRoot %>/dist/<%= appExpoName %>.apk"
},
<% } %>
Expand Down Expand Up @@ -97,11 +97,11 @@
},
<% if (framework === 'expo') { %>
"android.emu.eas": {
"device": "simulator",
"device": "emulator",
"app": "android.eas"
},
"android.emu.local": {
"device": "simulator",
"device": "emulator",
"app": "android.local"
},
<% } %>
Expand Down
45 changes: 45 additions & 0 deletions packages/detox/src/generators/application/lib/get-targets.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expoBuildTarget, expoTestTarget } from './get-targets';

describe('getTargets', () => {
it('should return ios test target for expo projects', () => {
expect(expoTestTarget('ios.sim', 'test')).toEqual({
options: {
detoxConfiguration: 'ios.sim.eas',
buildTarget: 'test:build-ios',
},
configurations: {
local: {
detoxConfiguration: 'ios.sim.local',
buildTarget: 'test:build-ios:local',
},
bare: {
detoxConfiguration: 'ios.sim.debug',
buildTarget: 'test:build-ios:bare',
},
production: {
detoxConfiguration: 'ios.sim.release',
buildTarget: 'test:build-ios:production',
},
},
});
});

it('should return ios build target for expo projects', () => {
expect(expoBuildTarget('ios.sim')).toEqual({
options: {
detoxConfiguration: 'ios.sim.eas',
},
configurations: {
local: {
detoxConfiguration: 'ios.sim.local',
},
bare: {
detoxConfiguration: 'ios.sim.debug',
},
production: {
detoxConfiguration: 'ios.sim.release',
},
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function reactNativeBuildTarget(platform: 'ios.sim' | 'android.emu') {
export function expoBuildTarget(platform: 'ios.sim' | 'android.emu') {
return {
options: {
detoxConfiguration: `${platform}.debug`,
detoxConfiguration: `${platform}.eas`,
},
configurations: {
local: {
Expand Down
8 changes: 6 additions & 2 deletions packages/detox/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { jestVersion, typesNodeVersion } from '@nx/jest/src/utils/versions';

import { Schema } from './schema';
import {
configPluginsDetoxVersion,
detoxVersion,
nxVersion,
testingLibraryJestDom,
Expand All @@ -21,7 +22,7 @@ export async function detoxInitGenerator(host: Tree, schema: Schema) {

if (!schema.skipPackageJson) {
tasks.push(moveDependency(host));
tasks.push(updateDependencies(host));
tasks.push(updateDependencies(host, schema));
}

if (!schema.skipFormat) {
Expand All @@ -31,7 +32,7 @@ export async function detoxInitGenerator(host: Tree, schema: Schema) {
return runTasksInSerial(...tasks);
}

export function updateDependencies(host: Tree) {
export function updateDependencies(host: Tree, schema: Schema) {
return addDependenciesToPackageJson(
host,
{},
Expand All @@ -41,6 +42,9 @@ export function updateDependencies(host: Tree) {
'@testing-library/jest-dom': testingLibraryJestDom,
'@types/node': typesNodeVersion,
'jest-circus': jestVersion,
...(schema.framework === 'expo'
? { '@config-plugins/detox': configPluginsDetoxVersion }
: {}),
}
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/detox/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface Schema {
skipFormat?: boolean;
skipPackageJson?: boolean; //default is false
framework?: 'react-native' | 'expo';
}
6 changes: 6 additions & 0 deletions packages/detox/src/generators/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"default": false,
"description": "Do not add dependencies to `package.json`.",
"x-priority": "internal"
},
"framework": {
"type": "string",
"description": "App framework to test",
"enum": ["react-native", "expo"],
"default": "react-native"
}
},
"required": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Update detoxrc for detox 20', () => {
sourceRoot: 'apps/products/src',
targets: {
'test-ios': {
executor: '@nrwl/detox:test',
executor: '@nx/detox:test',
},
},
});
Expand All @@ -31,6 +31,10 @@ describe('Update detoxrc for detox 20', () => {
'<rootDir>/src/**/*.test.ts?(x)',
'<rootDir>/src/**/*.spec.ts?(x)',
],
globalSetup: 'detox/runners/jest/globalSetup',
globalTeardown: 'detox/runners/jest/globalTeardown',
reporter: ['detox/runners/jest/reporter'],
verbose: true,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import {
* - update keys: runnerConfig
* Update jest.config.json under detox project:
* - remove key: transform
* - add key: rootDir, testMatch
* - add key: rootDir, testMatch, reporter, globalSetup, globalTeardown, verbose
*/
export default async function update(tree: Tree) {
const projects = getProjects(tree);

projects.forEach((project) => {
if (project.targets?.['test-ios']?.executor !== '@nrwl/detox:test') return;
if (project.targets?.['test-ios']?.executor !== '@nx/detox:test') return;
updateDetoxrcJson(tree, project);
updateJestConfigJson(tree, project);
});
Expand Down Expand Up @@ -62,6 +62,10 @@ function updateJestConfigJson(host: Tree, project: ProjectConfiguration) {
'<rootDir>/src/**/*.spec.ts?(x)',
];
}
json.reporter = ['detox/runners/jest/reporter'];
json.globalSetup = 'detox/runners/jest/globalSetup';
json.globalTeardown = 'detox/runners/jest/globalTeardown';
json.verbose = true;
return json;
});
}
Loading

0 comments on commit da912b2

Please sign in to comment.