-
Notifications
You must be signed in to change notification settings - Fork 98
Hansl/node e2e #355
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
Merged
Merged
Hansl/node e2e #355
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
200ad01
test: add e2e node tests.
317d0b0
fixup! test: add e2e node tests.
hansl bbb7442
fixup! test: add e2e node tests.
hansl 5630bba
Merge remote-tracking branch 'origin/master' into hansl/node-e2e
hansl 8144d5e
fixup! test: add e2e node tests.
hansl dfcd728
Merge remote-tracking branch 'origin/master' into hansl/node-e2e
hansl fab41f2
fixup! test: add e2e node tests.
hansl c56e220
fixup! test: add e2e node tests.
hansl f978021
fixup! test: add e2e node tests.
hansl 06cf02b
docs: adding documentation on the node e2e framework
hansl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| = Node End-to-End Tests | ||
|
|
||
| == High level overview | ||
|
|
||
| These tests are composed of two parts; | ||
|
|
||
| 1. a Nix script that installs the Userlib in the execution location, as if it was an NPM | ||
| package. This is done by building the NPM Package, and the JS Userlib derivation outputting | ||
| 2 outputs; the NPM package itself (in a packed format), and its node_modules which are | ||
| then copied in the execution folder for these tests. | ||
| 2. a Jest framework in TypeScript that runs and validate the tests. | ||
|
|
||
| The result is you build your tests as you would with Jest. You can import the JavaScript | ||
| userlib by using `import * as userlib from '@internet-computer/userlib'` which is as | ||
| close as it can be to the real world. | ||
|
|
||
| == Starting / Stopping the Replica | ||
|
|
||
| The `setup` Jest step starts the replica using `dfx replica`. The `teardown` step sends | ||
| a SIGTERM to the `dfx` process. Nix will wait for all children and descendants to be | ||
| stopped, so Nix will timeout and fail if the replica isn't properly killed. | ||
|
|
||
| == Adding New Tests | ||
|
|
||
| Adding a test is just a matter of having a file with a `.ts` extension anywhere outside | ||
| the root directory of tests and the `utils/` folder. This is driven by the | ||
| `jest.config.js` file which has a pattern matching all those files. | ||
|
|
||
| We don't force users to have a `.test.ts` extension as this whole folder is meant to be | ||
| tests. It's just simpler that way. | ||
|
|
||
| == Using HttpAgent | ||
|
|
||
| The `utils/` folder contain an `agent.ts` file which exports an `HttpAgent` instance | ||
| which connects to the testing Replica. Unless required by your test to have a special | ||
| agent configuration, you should always reuse that one. | ||
|
|
||
| == Creating and Using Canisters | ||
|
|
||
| Right now, the way to add a canister is to manually build it and check in the canisters | ||
| WASM. This is a limitation of the current setup and will (hopefully) go away soon. | ||
|
|
||
| Once the WASM is checked in, a canister `.ts` should be added which exports a factory. | ||
| That factory reads the WASM, creates an actor with a random canisterId, builds the IDL | ||
| manually (currently) and install the canister on the Replica. A good example of this | ||
| can be seen in `utils/canisters/counter.ts`. | ||
|
|
||
| = TODOs | ||
|
|
||
| - [ ] Adding linting and prettier to standardize syntax. | ||
| - [ ] Add a dfx project derivation which generates the WASM and IDL through Nix | ||
| so it doesn't have to be checked in. | ||
| - [ ] Also, reuse canister IDs exposed by the dfx project derivation above instead | ||
| of generating a random one. This is important for testing canisters which | ||
| have inter-canister calls. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import counterFactory from '../utils/canisters/counter'; | ||
|
|
||
| test('can call a canister', async () => { | ||
| let counter = await counterFactory(); | ||
|
|
||
| expect(+(await counter.read())).toEqual(0); | ||
| expect(+(await counter.inc_read())).toEqual(1); | ||
| await counter.write(10); | ||
| expect(+(await counter.read())).toEqual(10); | ||
| expect(+(await counter.inc_read())).toEqual(11); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| { pkgs ? import ../../nix { inherit system; } | ||
| , system ? builtins.currentSystem | ||
| , dfx ? import ../../dfx.nix { inherit pkgs; } | ||
| , userlib-js ? import ../../src/userlib/js { inherit pkgs; } | ||
| }: | ||
| let | ||
| e2e = pkgs.lib.noNixFiles (pkgs.lib.gitOnlySource ../../. ./.); | ||
| inputs = with pkgs; [ | ||
| coreutils | ||
| dfx.standalone | ||
| nodejs-12_x | ||
| ]; | ||
| in | ||
|
|
||
| pkgs.napalm.buildPackage e2e { | ||
| root = ./.; | ||
| name = "node-e2e-tests"; | ||
| buildInputs = inputs; | ||
| PATH = pkgs.lib.makeSearchPath "bin" inputs; | ||
|
|
||
| npmCommands = [ | ||
| "npm install" | ||
|
|
||
| # Monkey-patch the userlib source into our install dir. napalm is unable | ||
| # to include dependencies from package-locks in places other than the | ||
| # build root. | ||
| ( | ||
| pkgs.writeScript "include-userlib.sh" '' | ||
| #!${pkgs.stdenv.shell} | ||
| set -eo pipefail | ||
|
|
||
| userlib="node_modules/@internet-computer/userlib" | ||
| mkdir -p $userlib | ||
|
|
||
| tar xvzf ${userlib-js.out}/internet-computer-*.tgz --strip-component 1 --directory $userlib/ | ||
| cp -R ${userlib-js.lib}/node_modules . | ||
| '' | ||
| ) | ||
| "npm run ci" | ||
| ]; | ||
|
|
||
| installPhase = '' | ||
| echo Done. | ||
| touch $out | ||
| ''; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| module.exports = { | ||
| bail: false, | ||
| testTimeout: 60000, | ||
| globalSetup: './setup', | ||
| globalTeardown: './teardown', | ||
| setupFiles: [ | ||
| "./test-setup", | ||
| ], | ||
| setupFilesAfterEnv: [ | ||
| "jest-expect-message", | ||
| ], | ||
| // Since we're running e2e tests, ALL typescript files are up for grab. | ||
| testMatch: [ | ||
| "**/*.ts" | ||
| ], | ||
| testPathIgnorePatterns: [ | ||
| "/node_modules/", | ||
| "/utils/", | ||
| ], | ||
| transform: { | ||
| "^.+\\.ts$": "ts-jest" | ||
| } | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.