Skip to content

Commit

Permalink
chore(react-native): update react-native plugin unit tests to use "as…
Browse files Browse the repository at this point in the history
…-provided" (#18945)
  • Loading branch information
ndcunningham authored Aug 31, 2023
1 parent b17b30d commit fef332e
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('app', () => {
let appTree: Tree;

beforeEach(() => {
appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
appTree = createTreeWithEmptyWorkspace();
appTree.write('.gitignore', '');
});

Expand All @@ -23,10 +23,11 @@ describe('app', () => {
linter: Linter.EsLint,
e2eTestRunner: 'none',
install: false,
projectNameAndRootFormat: 'as-provided',
});
const projects = getProjects(appTree);

expect(projects.get('my-app').root).toEqual('apps/my-app');
expect(projects.get('my-app').root).toEqual('my-app');
});

it('should update nx.json', async () => {
Expand All @@ -37,6 +38,7 @@ describe('app', () => {
linter: Linter.EsLint,
e2eTestRunner: 'none',
install: false,
projectNameAndRootFormat: 'as-provided',
});

const projectConfiguration = readProjectConfiguration(appTree, 'my-app');
Expand All @@ -52,15 +54,16 @@ describe('app', () => {
linter: Linter.EsLint,
e2eTestRunner: 'none',
install: false,
projectNameAndRootFormat: 'as-provided',
});
expect(appTree.exists('apps/my-app/src/app/App.tsx')).toBeTruthy();
expect(appTree.exists('apps/my-app/src/main.tsx')).toBeTruthy();
expect(appTree.exists('my-app/src/app/App.tsx')).toBeTruthy();
expect(appTree.exists('my-app/src/main.tsx')).toBeTruthy();

const tsconfig = readJson(appTree, 'apps/my-app/tsconfig.json');
expect(tsconfig.extends).toEqual('../../tsconfig.base.json');
const tsconfig = readJson(appTree, 'my-app/tsconfig.json');
expect(tsconfig.extends).toEqual('../tsconfig.base.json');

expect(appTree.exists('apps/my-app/.eslintrc.json')).toBe(true);
expect(appTree.read('apps/my-app/jest.config.ts', 'utf-8'))
expect(appTree.exists('my-app/.eslintrc.json')).toBe(true);
expect(appTree.read('my-app/jest.config.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"module.exports = {
displayName: 'my-app',
Expand All @@ -71,7 +74,7 @@ describe('app', () => {
moduleNameMapper: {
'\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock',
},
coverageDirectory: '../../coverage/apps/my-app',
coverageDirectory: '../coverage/my-app',
};
"
`);
Expand All @@ -84,6 +87,7 @@ describe('app', () => {
linter: Linter.EsLint,
e2eTestRunner: 'none',
install: false,
projectNameAndRootFormat: 'as-provided',
});
const targets = readProjectConfiguration(appTree, 'my-app').targets;
expect(targets.test).toBeDefined();
Expand All @@ -98,10 +102,11 @@ describe('app', () => {
linter: Linter.EsLint,
e2eTestRunner: 'none',
install: false,
projectNameAndRootFormat: 'as-provided',
});

const tsconfig = readJson(appTree, 'apps/my-app/tsconfig.json');
expect(tsconfig.extends).toEqual('../../tsconfig.json');
const tsconfig = readJson(appTree, 'my-app/tsconfig.json');
expect(tsconfig.extends).toEqual('../tsconfig.json');
});

describe('detox', () => {
Expand All @@ -112,49 +117,45 @@ describe('app', () => {
linter: Linter.EsLint,
e2eTestRunner: 'detox',
install: false,
projectNameAndRootFormat: 'as-provided',
});

const projects = getProjects(appTree);
expect(projects.get('my-dir-my-app').root).toEqual('apps/my-dir/my-app');

expect(
appTree.exists('apps/my-dir/my-app-e2e/.detoxrc.json')
).toBeTruthy();
const detoxrc = appTree.read(
'apps/my-dir/my-app-e2e/.detoxrc.json',
'utf-8'
);
expect(projects.get('my-app').root).toEqual('my-dir');

expect(appTree.exists('my-dir-e2e/.detoxrc.json')).toBeTruthy();
const detoxrc = appTree.read('my-dir-e2e/.detoxrc.json', 'utf-8');
// Strip trailing commas
const detoxrcJson = JSON.parse(
detoxrc.replace(/(?<=(true|false|null|["\d}\]])\s*),(?=\s*[}\]])/g, '')
);
expect(detoxrcJson.apps).toEqual({
'android.debug': {
binaryPath:
'../../../apps/my-dir/my-app/android/app/build/outputs/apk/debug/app-debug.apk',
'../my-dir/android/app/build/outputs/apk/debug/app-debug.apk',
build:
'cd ../../../apps/my-dir/my-app/android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
'cd ../my-dir/android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
type: 'android.apk',
},
'android.release': {
binaryPath:
'../../../apps/my-dir/my-app/android/app/build/outputs/apk/release/app-release.apk',
'../my-dir/android/app/build/outputs/apk/release/app-release.apk',
build:
'cd ../../../apps/my-dir/my-app/android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release',
'cd ../my-dir/android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release',
type: 'android.apk',
},
'ios.debug': {
binaryPath:
'../../../apps/my-dir/my-app/ios/build/Build/Products/Debug-iphonesimulator/MyApp.app',
'../my-dir/ios/build/Build/Products/Debug-iphonesimulator/MyApp.app',
build:
"cd ../../../apps/my-dir/my-app/ios && xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath ./build -quiet",
"cd ../my-dir/ios && xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath ./build -quiet",
type: 'ios.app',
},
'ios.release': {
binaryPath:
'../../../apps/my-dir/my-app/ios/build/Build/Products/Release-iphonesimulator/MyApp.app',
'../my-dir/ios/build/Build/Products/Release-iphonesimulator/MyApp.app',
build:
"cd ../../../apps/my-dir/my-app/ios && xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath ./build -quiet",
"cd ../my-dir/ios && xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath ./build -quiet",
type: 'ios.app',
},
});
Expand All @@ -166,43 +167,44 @@ describe('app', () => {
linter: Linter.EsLint,
e2eTestRunner: 'detox',
install: false,
projectNameAndRootFormat: 'as-provided',
});

const projects = getProjects(appTree);
expect(projects.get('my-app').root).toEqual('apps/my-app');
expect(projects.get('my-app').root).toEqual('my-app');

const detoxrc = appTree.read('apps/my-app-e2e/.detoxrc.json', 'utf-8');
const detoxrc = appTree.read('my-app-e2e/.detoxrc.json', 'utf-8');
// Strip trailing commas
const detoxrcJson = JSON.parse(
detoxrc.replace(/(?<=(true|false|null|["\d}\]])\s*),(?=\s*[}\]])/g, '')
);
expect(detoxrcJson.apps).toEqual({
'android.debug': {
binaryPath:
'../../apps/my-app/android/app/build/outputs/apk/debug/app-debug.apk',
'../my-app/android/app/build/outputs/apk/debug/app-debug.apk',
build:
'cd ../../apps/my-app/android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
'cd ../my-app/android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
type: 'android.apk',
},
'android.release': {
binaryPath:
'../../apps/my-app/android/app/build/outputs/apk/release/app-release.apk',
'../my-app/android/app/build/outputs/apk/release/app-release.apk',
build:
'cd ../../apps/my-app/android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release',
'cd ../my-app/android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release',
type: 'android.apk',
},
'ios.debug': {
binaryPath:
'../../apps/my-app/ios/build/Build/Products/Debug-iphonesimulator/MyApp.app',
'../my-app/ios/build/Build/Products/Debug-iphonesimulator/MyApp.app',
build:
"cd ../../apps/my-app/ios && xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath ./build -quiet",
"cd ../my-app/ios && xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath ./build -quiet",
type: 'ios.app',
},
'ios.release': {
binaryPath:
'../../apps/my-app/ios/build/Build/Products/Release-iphonesimulator/MyApp.app',
'../my-app/ios/build/Build/Products/Release-iphonesimulator/MyApp.app',
build:
"cd ../../apps/my-app/ios && xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath ./build -quiet",
"cd ../my-app/ios && xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath ./build -quiet",
type: 'ios.app',
},
});
Expand All @@ -220,6 +222,7 @@ describe('app', () => {
e2eTestRunner: 'none',
install: false,
skipPackageJson: true,
projectNameAndRootFormat: 'as-provided',
});

expect(readJson(appTree, 'package.json')).toEqual(packageJsonBefore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Normalize Options', () => {
let appTree: Tree;

beforeEach(() => {
appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
appTree = createTreeWithEmptyWorkspace();
});

it('should normalize options with name in kebab case', async () => {
Expand All @@ -17,19 +17,20 @@ describe('Normalize Options', () => {
linter: Linter.EsLint,
e2eTestRunner: 'none',
install: false,
projectNameAndRootFormat: 'as-provided',
};
const options = await normalizeOptions(appTree, schema);
expect(options).toEqual({
androidProjectRoot: 'apps/my-app/android',
appProjectRoot: 'apps/my-app',
androidProjectRoot: 'my-app/android',
appProjectRoot: 'my-app',
className: 'MyApp',
displayName: 'MyApp',
iosProjectRoot: 'apps/my-app/ios',
iosProjectRoot: 'my-app/ios',
lowerCaseName: 'myapp',
name: 'my-app',
parsedTags: [],
projectName: 'my-app',
projectNameAndRootFormat: 'derived',
projectNameAndRootFormat: 'as-provided',
linter: Linter.EsLint,
entryFile: 'src/main.tsx',
e2eTestRunner: 'none',
Expand All @@ -43,19 +44,20 @@ describe('Normalize Options', () => {
name: 'myApp',
e2eTestRunner: 'none',
install: false,
projectNameAndRootFormat: 'as-provided',
};
const options = await normalizeOptions(appTree, schema);
expect(options).toEqual({
androidProjectRoot: 'apps/my-app/android',
appProjectRoot: 'apps/my-app',
androidProjectRoot: 'my-app/android',
appProjectRoot: 'my-app',
className: 'MyApp',
displayName: 'MyApp',
iosProjectRoot: 'apps/my-app/ios',
iosProjectRoot: 'my-app/ios',
lowerCaseName: 'myapp',
name: 'my-app',
parsedTags: [],
projectName: 'my-app',
projectNameAndRootFormat: 'derived',
projectNameAndRootFormat: 'as-provided',
entryFile: 'src/main.tsx',
e2eTestRunner: 'none',
unitTestRunner: 'jest',
Expand All @@ -66,23 +68,24 @@ describe('Normalize Options', () => {
it('should normalize options with directory', async () => {
const schema: Schema = {
name: 'my-app',
directory: 'directory',
directory: 'directory/my-app',
e2eTestRunner: 'none',
install: false,
projectNameAndRootFormat: 'as-provided',
};
const options = await normalizeOptions(appTree, schema);
expect(options).toEqual({
androidProjectRoot: 'apps/directory/my-app/android',
appProjectRoot: 'apps/directory/my-app',
androidProjectRoot: 'directory/my-app/android',
appProjectRoot: 'directory/my-app',
className: 'MyApp',
displayName: 'MyApp',
iosProjectRoot: 'apps/directory/my-app/ios',
iosProjectRoot: 'directory/my-app/ios',
lowerCaseName: 'myapp',
name: 'my-app',
directory: 'directory',
directory: 'directory/my-app',
parsedTags: [],
projectName: 'directory-my-app',
projectNameAndRootFormat: 'derived',
projectName: 'my-app',
projectNameAndRootFormat: 'as-provided',
entryFile: 'src/main.tsx',
e2eTestRunner: 'none',
unitTestRunner: 'jest',
Expand All @@ -95,19 +98,20 @@ describe('Normalize Options', () => {
name: 'directory/my-app',
e2eTestRunner: 'none',
install: false,
projectNameAndRootFormat: 'as-provided',
};
const options = await normalizeOptions(appTree, schema);
expect(options).toEqual({
androidProjectRoot: 'apps/directory/my-app/android',
appProjectRoot: 'apps/directory/my-app',
androidProjectRoot: 'directory/my-app/android',
appProjectRoot: 'directory/my-app',
className: 'DirectoryMyApp',
displayName: 'DirectoryMyApp',
iosProjectRoot: 'apps/directory/my-app/ios',
iosProjectRoot: 'directory/my-app/ios',
lowerCaseName: 'directorymyapp',
name: 'directory/my-app',
parsedTags: [],
projectName: 'directory-my-app',
projectNameAndRootFormat: 'derived',
projectName: 'directory/my-app',
projectNameAndRootFormat: 'as-provided',
entryFile: 'src/main.tsx',
e2eTestRunner: 'none',
unitTestRunner: 'jest',
Expand All @@ -121,19 +125,20 @@ describe('Normalize Options', () => {
displayName: 'My App',
e2eTestRunner: 'none',
install: false,
projectNameAndRootFormat: 'as-provided',
};
const options = await normalizeOptions(appTree, schema);
expect(options).toEqual({
androidProjectRoot: 'apps/my-app/android',
appProjectRoot: 'apps/my-app',
androidProjectRoot: 'my-app/android',
appProjectRoot: 'my-app',
className: 'MyApp',
displayName: 'My App',
iosProjectRoot: 'apps/my-app/ios',
iosProjectRoot: 'my-app/ios',
lowerCaseName: 'myapp',
name: 'my-app',
parsedTags: [],
projectName: 'my-app',
projectNameAndRootFormat: 'derived',
projectNameAndRootFormat: 'as-provided',
entryFile: 'src/main.tsx',
e2eTestRunner: 'none',
unitTestRunner: 'jest',
Expand Down
Loading

0 comments on commit fef332e

Please sign in to comment.