From 9d2095500f8611d75f34b77d144426275eb5eee2 Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Mon, 18 Dec 2023 15:49:36 +0100 Subject: [PATCH] fix(test): update snapshots --- .../__snapshots__/editTemplate.test.ts.snap | 60 +++++++++++++++++-- .../init/__tests__/editTemplate.test.ts | 52 ++++++++++++++++ 2 files changed, 106 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/commands/init/__tests__/__snapshots__/editTemplate.test.ts.snap b/packages/cli/src/commands/init/__tests__/__snapshots__/editTemplate.test.ts.snap index ebd8a59140..b36e4bafd4 100644 --- a/packages/cli/src/commands/init/__tests__/__snapshots__/editTemplate.test.ts.snap +++ b/packages/cli/src/commands/init/__tests__/__snapshots__/editTemplate.test.ts.snap @@ -21,6 +21,30 @@ exports[`should edit template 1`] = ` - First value + Second value +@@ -515,12 +515,8 @@ + 80, +- 108, +- 97, +- 99, +- 101, +- 104, ++ 114, + 111, +- 108, +- 100, ++ 106, + 101, +- 114, ++ 99, ++ 116, + 78," +`; + +exports[`should edit template 2`] = ` +"Snapshot Diff: +- First value ++ Second value + @@ -12,3 +12,3 @@ RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge - moduleName:@\\"PlaceholderName\\" @@ -28,7 +52,7 @@ exports[`should edit template 1`] = ` initialProperties:nil];" `; -exports[`should edit template 2`] = ` +exports[`should edit template 3`] = ` "Snapshot Diff: - First value + Second value @@ -40,13 +64,13 @@ exports[`should edit template 2`] = ` " `; -exports[`should edit template 3`] = ` +exports[`should edit template 4`] = ` "Snapshot Diff: - First value + Second value -@@ -9,5 +9,5 @@ - \\"/android/android-java/com/.DS_Store\\", +@@ -8,5 +8,5 @@ + \\"/android/android-java/com\\", - \\"/android/android-java/com/placeholdername\\", - \\"/android/android-java/com/placeholdername/MainActivity.java\\", - \\"/android/android-java/com/placeholdername/PlaceholderName.java\\", @@ -54,8 +78,8 @@ exports[`should edit template 3`] = ` + \\"/android/android-java/com/projectname/MainActivity.java\\", + \\"/android/android-java/com/projectname/ProjectName.java\\", \\"/android/android-kotlin\\", -@@ -16,14 +16,14 @@ - \\"/android/android-kotlin/com/.DS_Store\\", +@@ -14,14 +14,14 @@ + \\"/android/android-kotlin/com\\", - \\"/android/android-kotlin/com/placeholdername\\", - \\"/android/android-kotlin/com/placeholdername/MainActivity.kt\\", - \\"/android/android-kotlin/com/placeholdername/PlaceholderName.kt\\", @@ -80,3 +104,27 @@ exports[`should edit template 3`] = ` + \\"/ios/ProjectNameTests/.gitkeep\\", \\"/node_modules\\"," `; + +exports[`should edit template with custom title 1`] = ` +"Snapshot Diff: +- First value ++ Second value + +@@ -515,12 +515,8 @@ + 80, +- 108, +- 97, +- 99, +- 101, +- 104, ++ 114, + 111, +- 108, +- 100, ++ 106, + 101, +- 114, ++ 99, ++ 116, + 78," +`; diff --git a/packages/cli/src/commands/init/__tests__/editTemplate.test.ts b/packages/cli/src/commands/init/__tests__/editTemplate.test.ts index db2d2f2c33..de152070b7 100644 --- a/packages/cli/src/commands/init/__tests__/editTemplate.test.ts +++ b/packages/cli/src/commands/init/__tests__/editTemplate.test.ts @@ -55,6 +55,28 @@ test('should edit template', async () => { const transformedTree = walk(testPath).map((e) => e.replace(testPath, '')); const fixtureTree = walk(FIXTURE_DIR).map((e) => e.replace(FIXTURE_DIR, '')); + const oldJavaFile = fs.readFileSync( + path.resolve( + FIXTURE_DIR, + 'android', + 'android-java', + 'com', + PLACEHOLDER_NAME.toLowerCase(), + 'MainActivity.java', + ), + ); + + const newJavaFile = fs.readFileSync( + path.resolve( + testPath, + 'android', + 'android-java', + 'com', + PROJECT_NAME.toLowerCase(), + 'MainActivity.java', + ), + ); + const oldXmlFile = fs.readFileSync( path.resolve(FIXTURE_DIR, 'android', 'strings.xml'), 'utf8', @@ -73,6 +95,10 @@ test('should edit template', async () => { 'utf8', ); + expect( + snapshotDiff(oldJavaFile, newJavaFile, {contextLines: 1}), + ).toMatchSnapshot(); + expect(snapshotDiff(oldCFile, newCFile, {contextLines: 1})).toMatchSnapshot(); expect( snapshotDiff(oldXmlFile, newXmlFile, {contextLines: 1}), @@ -93,11 +119,37 @@ test('should edit template with custom title', async () => { projectTitle: PROJECT_TITLE, }); + const oldJavaFile = fs.readFileSync( + path.resolve( + FIXTURE_DIR, + 'android', + 'android-java', + 'com', + PLACEHOLDER_NAME.toLowerCase(), + 'MainActivity.java', + ), + ); + + const newJavaFile = fs.readFileSync( + path.resolve( + testPath, + 'android', + 'android-java', + 'com', + PROJECT_NAME.toLowerCase(), + 'MainActivity.java', + ), + ); + const replacedFile = fs.readFileSync( path.resolve(testPath, 'android', 'strings.xml'), 'utf8', ); + expect( + snapshotDiff(oldJavaFile, newJavaFile, {contextLines: 1}), + ).toMatchSnapshot(); + expect(replacedFile).toContain( `${PROJECT_TITLE}`, );