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

Improve running tests when server is missing #6494

Merged
merged 10 commits into from
Feb 20, 2024

Conversation

kraenhansen
Copy link
Member

@kraenhansen kraenhansen commented Feb 19, 2024

What, How & Why?

I want to improve the default experience of running our tests.
Unfortunately, contributors to the project isn't allowed to pull the docker image and run the test server, but that shouldn't keep them from running tests at all. In its current form, its a subtly documented feature of the test runner that you can run with missingServer context, but I want to make this more obvious and improve the default experience (when the server is missing).

If the environment does not explicitly provide a baseUrl nor set missingServer=false the tests using importAppBefore will skip if the app import fails due to a connection refusal. If this happens, a warning will be printed after all tests has ran:

Screenshot 2024-02-19 at 11 38 53

  • This PR also renames realmBaseUrl to baseUrl since theres only ever one base url, so there's no need to disambiguate it and the latter is the name used in the code anyway.
  • It also simplifies how tests are skipped when ran with missingServer, to include this check in the importAppBefore hook as they were (almost) always used together anyway and could easily be forgotten.

☑️ ToDos

  • 📝 Changelog entry
  • 📝 Compatibility label is updated or copied from previous entry
  • 📝 Update COMPATIBILITY.md
  • 🚦 Tests
  • 📦 Updated internal package version in consuming package.jsons (if updating internal packages)
  • 📱 Check the React Native/other sample apps work if necessary
  • 💥 Breaking label has been applied or is not necessary

@kraenhansen kraenhansen merged commit 4df2094 into main Feb 20, 2024
31 checks passed
@kraenhansen kraenhansen deleted the kh/skip-tests-missing-server branch February 20, 2024 19:47
@kraenhansen
Copy link
Member Author

I'll merge to improve our DX tomorrow 🙈 Feel free to review in retrospect (or not 😊).

Copy link
Contributor

@elle-j elle-j left a comment

Choose a reason for hiding this comment

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

Nice DX improvement 👍

Comment on lines +49 to +65
function getCredentials(): Credentials {
if (typeof publicKey === "string" && typeof privateKey === "string") {
return {
kind: "api-key",
publicKey,
privateKey,
};
} else {
return {
kind: "username-password",
username,
password,
};
}
}

const credentials = getCredentials();
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the function is only used once, so it may not need to be a function.

Suggested change
function getCredentials(): Credentials {
if (typeof publicKey === "string" && typeof privateKey === "string") {
return {
kind: "api-key",
publicKey,
privateKey,
};
} else {
return {
kind: "username-password",
username,
password,
};
}
}
const credentials = getCredentials();
const credentials: Credentials =
typeof publicKey === "string" && typeof privateKey === "string"
? { kind: "api-key", publicKey, privateKey }
: { kind: "username-password", username, password };

);
}

function printWarningBox(...lines: string[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to utilize this elsewhere as well, could we move this into /utils? 🙂

describe("Logging", () => {
importAppBefore(buildAppConfig("with-pbs").anonAuth().flexibleSync());
afterEach(() => Realm.clearTestState());
// Skipped because reusing a single app across tests break this
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Skipped because reusing a single app across tests break this

kraenhansen added a commit that referenced this pull request Feb 29, 2024
kraenhansen added a commit that referenced this pull request Feb 29, 2024
bimusiek pushed a commit to bimusiek/realm-js that referenced this pull request Mar 14, 2024
* Moved app import util into the hook

* Moved skipping tests on missingServer into importAppBefore hook

* Skip tests which importAppBefore when failing to install

* Renamed "realmBaseUrl" to "baseUrl"

* Fix closing a realm if import skips it completely

* Moved testing non-existing app id into "with valid app"

* Printing warning after all tests

* Fixed "allowSkippingServerTests"

* Adding documentation to importAppBefore

* Moved "Logging" test out of "SessionTest" because the importApp function has gone away
bimusiek pushed a commit to bimusiek/realm-js that referenced this pull request Mar 14, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants