forked from polkadot-js/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A proof of concept for frontend test with substrate in docker (polkad…
…ot-js#3371) * React tests PoC. * Globally start and stop substrate for all tests. * Fix compilation problem. * Another attempt to make both compilation and tests work. * Apply suggestions from code review * Run slow tests with docker only nightly. * Update yarn.lock. Co-authored-by: Jaco Greeff <[email protected]>
- Loading branch information
1 parent
f79e6ea
commit 8b50b1b
Showing
12 changed files
with
401 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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,19 @@ | ||
name: Nightly tests run | ||
on: | ||
schedule: | ||
- cron: '1 5 * * *' | ||
|
||
|
||
jobs: | ||
alltests: | ||
strategy: | ||
matrix: | ||
step: ['test:all'] | ||
name: ${{ matrix.step }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: ${{ matrix.step }} | ||
run: | | ||
yarn install --immutable | grep -v 'YN0013' | ||
yarn ${{ matrix.step }} |
This file contains 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,6 @@ | ||
// Copyright 2019-2020 @polkadot/extension authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
// eslint-disable-line | ||
module.exports = ''; |
This file contains 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
This file contains 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,28 @@ | ||
// Copyright 2017-2020 @polkadot/app-accounts authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { GenericContainer, Wait } from 'testcontainers'; | ||
import { SubstrateTestsGlobal } from './substrateTestsGlobal'; | ||
|
||
declare const global: SubstrateTestsGlobal; | ||
|
||
const startSubstrate = async () => { | ||
console.log('Substrate container starting...'); | ||
|
||
const startedTestContainer = await new GenericContainer('parity/substrate') | ||
.withName('polkadot-apps-test-substrate') | ||
.withExposedPorts(9944) | ||
.withCmd(['--dev', '--ws-port=9944', '--unsafe-ws-external']) | ||
.withWaitStrategy(Wait.forLogMessage('New epoch 0 launching')) | ||
.start(); | ||
|
||
console.log('Done.'); | ||
|
||
process.env.TEST_SUBSTRATE_PORT = startedTestContainer.getMappedPort(9944)?.toString() || ''; | ||
global.__SUBSTRATE__ = startedTestContainer; | ||
}; | ||
|
||
export default async (): Promise<void> => { | ||
await startSubstrate(); | ||
}; |
This file contains 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,15 @@ | ||
// Copyright 2017-2020 @polkadot/app-accounts authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { SubstrateTestsGlobal } from './substrateTestsGlobal'; | ||
|
||
declare const global: SubstrateTestsGlobal; | ||
|
||
export default async (): Promise<void> => { | ||
console.log('Shutting down Substrate container...'); | ||
|
||
await global.__SUBSTRATE__.stop(); | ||
|
||
console.log('Done.'); | ||
}; |
This file contains 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,10 @@ | ||
// Copyright 2017-2020 @polkadot/app-accounts authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { StartedTestContainer } from 'testcontainers'; | ||
|
||
export interface SubstrateTestsGlobal extends NodeJS.Global { | ||
__SUBSTRATE__: StartedTestContainer; | ||
// You can declare anything you need. | ||
} |
This file contains 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
This file contains 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
This file contains 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,63 @@ | ||
// Copyright 2017-2020 @polkadot/app-accounts authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import AccountsApp from '@polkadot/app-accounts'; | ||
import { MemoryStore } from '@polkadot/app-accounts/test-support/MemoryStore'; | ||
import { Api } from '@polkadot/react-api'; | ||
import '@polkadot/react-components/i18n'; | ||
import { useApi } from '@polkadot/react-hooks'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import React, { PropsWithChildren } from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
const SUBSTRATE_PORT = Number.parseInt(process.env.TEST_SUBSTRATE_PORT || '30333'); | ||
|
||
const WaitForApi = ({ children }: { children: React.ReactNode }): PropsWithChildren<any> | null => { | ||
const api = useApi(); | ||
|
||
return api.isApiReady ? (children) : null; | ||
}; | ||
|
||
describe('--SLOW--: Account Create', () => { | ||
it('asks for confirmation after saving new account', async () => { | ||
const memoryStore = new MemoryStore(); | ||
|
||
const { findByPlaceholderText, findByTestId, findByText } = render( | ||
<MemoryRouter> | ||
<Api store={memoryStore} | ||
url={`ws://127.0.0.1:${SUBSTRATE_PORT}`}> | ||
<WaitForApi> | ||
<div> | ||
<AccountsApp basePath='/accounts' | ||
onStatusChange={() => { /* */ | ||
}}/> | ||
</div> | ||
</WaitForApi> | ||
</Api> | ||
</MemoryRouter> | ||
); | ||
|
||
const addAccountButton = await findByText('Add account', {}, { timeout: 4000 }); | ||
|
||
fireEvent.click(addAccountButton); | ||
|
||
const nameInput = await findByPlaceholderText('new account'); | ||
|
||
fireEvent.change(nameInput, { target: { value: 'my super account' } }); | ||
|
||
const passwordInput = await findByTestId('password'); | ||
|
||
fireEvent.change(passwordInput, { target: { value: 'a' } }); | ||
|
||
const passwordRepeatInput = await findByTestId('password (repeat)'); | ||
|
||
fireEvent.change(passwordRepeatInput, { target: { value: 'a' } }); | ||
|
||
const saveButton = await findByText('Save'); | ||
|
||
fireEvent.click(saveButton); | ||
|
||
expect(await findByText('Create and backup account')).toBeTruthy(); | ||
}); | ||
}); |
This file contains 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,35 @@ | ||
// Copyright 2017-2020 @polkadot/app-accounts authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { KeyringJson, KeyringStore } from '@polkadot/ui-keyring/types'; | ||
|
||
type AccountsMap = Record<string, KeyringJson>; | ||
|
||
export class MemoryStore implements KeyringStore { | ||
private accounts: AccountsMap = {}; | ||
|
||
all (cb: (key: string, value: KeyringJson) => void): void { | ||
Object.keys(this.accounts).forEach((accountsKey) => cb(accountsKey, this.accounts[accountsKey])); | ||
} | ||
|
||
get (key: string, cb: (value: KeyringJson) => void): void { | ||
cb(this.accounts[key]); | ||
} | ||
|
||
remove (key: string, cb: (() => void) | undefined): void { | ||
delete this.accounts[key]; | ||
|
||
if (cb) { | ||
cb(); | ||
} | ||
} | ||
|
||
set (key: string, value: KeyringJson, cb: (() => void) | undefined): void { | ||
this.accounts[key] = value; | ||
|
||
if (cb) { | ||
cb(); | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.