Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start on getting a test harness in place #25

Merged
merged 10 commits into from
May 3, 2023
Merged

Start on getting a test harness in place #25

merged 10 commits into from
May 3, 2023

Conversation

nakajima
Copy link
Contributor

@nakajima nakajima commented May 1, 2023

Adds a screen in the RN example app where we can write tests. You can see the first couple of tests here.

You can also run the tests from Xcode, which just opens the example app, goes to the test screen then looks for failures (see here). In a follow up PR, we can wire up CI, I feel like this PR is big enough as is.

As part of getting tests working, I had to add support for letting multiple Client instances backed by the native client. That's some work we'll need to do on an Android side to get the tests to pass (cc @nplasterer).

Note: You'll need to run a local node for the tests.

Screenshot 2023-05-03 at 11 59 26 AM

Comment on lines +21 to +49
func testRunTests() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()

// Go to unit tests page
let button = app.buttons["Unit tests"]
XCTAssert(button.waitForExistence(timeout: 3))
button.tap()

// Make sure we're there
let view = app.staticTexts["Test View"]
XCTAssert(view.waitForExistence(timeout: 3))

// Wait for tests to complete
let complete = app.staticTexts["tests-complete"]
XCTAssert(complete.waitForExistence(timeout: 5))

// See if we have any failures
if app.staticTexts["FAIL"].waitForExistence(timeout: 3) {
// Take a screenshot so we can see what failed in the UI
let screenshot = app.windows.firstMatch.screenshot()
let attachment = XCTAttachment(screenshot: screenshot)
attachment.lifetime = .keepAlways
add(attachment)

XCTFail("Tests failed.")
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's where we run the tests in Xcode, it's what should be run by xcode cloud when we set up CI.

</View>
{result == "failure" && (
<Text
testID="FAIL"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what the Xcode runner looks for to determine failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the changes in this file were to handle supporting multiple clients.

@@ -2,6 +2,7 @@
{
"extends": "expo-module-scripts/tsconfig.base",
"compilerOptions": {
"lib": ["es2015", "DOM"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed this to fix some TS errors.

@nakajima nakajima marked this pull request as ready for review May 3, 2023 20:51
@nakajima nakajima requested a review from a team as a code owner May 3, 2023 20:51
Copy link
Contributor

@michaelx11 michaelx11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from my end

@@ -24,5 +24,5 @@ Pod::Spec.new do |s|
}

s.source_files = "**/*.{h,m,swift}"
s.dependency "XMTP", "= 0.1.3-beta0"
s.dependency "XMTP", "= 0.2.1-beta0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still confused why this works, because I still don't see a 0.2.1-beta0 version for the XMTP cocoapod: https://github.com/search?q=repo%3ACocoaPods%2FSpecs+XMTP&type=commits

But if it works it works!

tests.push({ name, run: perform });
}

// test("can fail", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: leftover commented code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this around for now just so I can uncomment it when I set up CI and make sure that's all working. Good eye though!

return client.address.length > 0;
});

test("can message a client", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Copy link
Contributor

@nplasterer nplasterer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me. Should probably add something to the read me about running the tests and running the local node for clarity when people clone/copy the code and can't get it working.

@nakajima nakajima merged commit c780980 into main May 3, 2023
@nakajima nakajima deleted the unittestharness branch May 3, 2023 23:00
@nplasterer nplasterer mentioned this pull request May 5, 2023
@github-actions
Copy link
Contributor

🎉 This PR is included in version 1.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants