Skip to content

Commit 216e773

Browse files
authored
Arnold isolated test (#102)
* .. * .. * .. * .. * .. * .. * .. * Undo changes * todo
1 parent b6c4240 commit 216e773

5 files changed

Lines changed: 38 additions & 12 deletions

File tree

android/app/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ android {
9595
versionCode 1
9696
versionName "1.0"
9797

98-
testInstrumentationRunner "com.rnstorybookautoscreenshots.BaseScreenshotTestRunner"
99-
testInstrumentationRunnerArguments useTestStorageService: "true"
98+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
10099
}
101100
signingConfigs {
102101
debug {

android/app/src/androidTest/java/com/testapp/IsolatedTest.kt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import junit.framework.TestCase.assertNotNull
77
import junit.framework.TestCase.assertTrue
88
import org.junit.Test
99
import org.junit.runner.RunWith
10+
import com.facebook.testing.screenshot.ViewHelpers
11+
import com.facebook.testing.screenshot.Screenshot
12+
import org.junit.Assert.*;
13+
import com.facebook.react.interfaces.*
1014

1115
@RunWith(AndroidJUnit4::class)
1216
class IsolatedTest {
@@ -20,7 +24,32 @@ class IsolatedTest {
2024
val context = InstrumentationRegistry.getInstrumentation().targetContext
2125
val app = context.applicationContext as MainApplication
2226
val surface = app.reactHost.createSurface(context, "SimpleTestComponent", null)
23-
surface.start()
27+
assertEquals("SimpleTestComponent", surface.moduleName)
28+
29+
// TODO: we aren't 100% sure if prerender() and start() are being called the way we want it to.
30+
// We probably want to create a ReactHost directly instead of taking it from the MainApplication... probably
31+
// Also look up bridge-less mode.
32+
assertGoodTask(surface.prerender())
33+
34+
2435
assertNotNull(surface.view)
36+
37+
ViewHelpers.setupView(surface.view!!)
38+
.setExactHeightPx(1000)
39+
.setExactWidthPx(1000)
40+
.layout()
41+
42+
43+
val ti = surface.start()
44+
assertGoodTask(ti)
45+
46+
Screenshot.snap(surface.view!!)
47+
.record()
2548
}
2649
}
50+
51+
fun assertGoodTask(ti : TaskInterface<Void>) {
52+
ti.waitForCompletion()
53+
assertFalse(ti.isFaulted())
54+
assertTrue(ti.isCompleted())
55+
}

android/app/src/androidTest/java/com/testapp/ScreenshotTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.junit.Rule
1515
import org.junit.Test
1616
import org.junit.runner.RunWith
1717

18+
@org.junit.Ignore
1819
@RunWith(AndroidJUnit4::class)
1920
class ScreenshotTest {
2021

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
package com.testapp
22

3-
import androidx.test.ext.junit.runners.AndroidJUnit4
4-
import com.rnstorybookautoscreenshots.BaseStoryScreenshotTest
5-
import org.junit.runner.RunWith
6-
7-
@RunWith(AndroidJUnit4::class)
8-
class StoryScreenshotTest : BaseStoryScreenshotTest()

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import { name as appName } from './app.json';
77

88
// Configure and register StoryRenderer for screenshot tests
99
const { view } = require('./.rnstorybook/storybook.requires');
10-
const { configure, StoryRenderer } = require('rn-storybook-auto-screenshots');
11-
configure(view);
12-
AppRegistry.registerComponent('StoryRenderer', () => StoryRenderer);
10+
11+
// TODO: bring this back. It was failing on Arnold's Android Studio builds, so while we were working on IsolatedTest,
12+
// we disabled it to keep the builds fast.
13+
// const { configure, StoryRenderer } = require('rn-storybook-auto-screenshots');
14+
// configure(view);
15+
// AppRegistry.registerComponent('StoryRenderer', () => StoryRenderer);
1316

1417
const SimpleTestComponent = () => <View><Text>Hello</Text></View>;
1518
AppRegistry.registerComponent('SimpleTestComponent', () => SimpleTestComponent);

0 commit comments

Comments
 (0)