Skip to content

Commit

Permalink
test(connect): fix karma setup
Browse files Browse the repository at this point in the history
- parametrize karma singleRun
- remove unused (mocha, browserConsoleLogOptions) from karma config
- karma fallback for `it.skip` and `it.only`
- fix import in fixtures
- fix filter and accept `testName.test` pattern
  • Loading branch information
szymonlesisz authored and mroz22 committed Sep 27, 2024
1 parent f62d8ff commit fb888be
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
10 changes: 10 additions & 0 deletions packages/connect/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ you may use the following params:
-i <in case -p methods, use -i to filter one connect method, such as -i binanceGetAddress>
```

## karma test

Browser console is not visible in the terminal. Use KARMA_SINGLE_RUN env variable and debug test at http://localhost:8099/debug.html in your favorite browser.

For local changes to take effect build connect-iframe or connect-web depending where they were made and restart test.

```
TESTS_PATTERN="init" KARMA_SINGLE_RUN=false yarn workspace @trezor/connect test:e2e:web
```

## Transactions cache

Bitcoin-like coins `signTransaction` method require additional data about transactions referenced from used inputs.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/prefer-ts-expect-error */
// @ts-ignore
import commonFixtures from '../../../../submodules/trezor-common/tests/fixtures/stellar/sign_tx.json';
import { Messages } from '@trezor/transport/src';
import * as Messages from '@trezor/protobuf/src/messages';

// operations are in protobuf format (snake_case)

Expand Down
15 changes: 4 additions & 11 deletions packages/connect/e2e/karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@ const path = require('path');
const webpack = require('webpack');

module.exports = config => {
const singleRun = process.env.KARMA_SINGLE_RUN === 'false' ? false : true;

config.set({
basePath: path.resolve(__dirname, '../..'), // NOTE: "[monorepo-root]/packages", to have access to other packages
hostname: 'localhost',
port: 8099,
autoWatch: false,
// to debug locally set single run to false and go to http://localhost:8099/debug.html
// for local changes to take effect build connect-iframe and connect-web
singleRun: true,
singleRun,

client: {
captureConsole: true,
clearContext: true,
useIframe: false,
runInParent: true,
mocha: {
bail: true,
},
// uncomment to disable random ordering of tests
jasmine: {
random: false,
},
},
browserConsoleLogOptions: {
terminal: true,
level: '',
},
browsers: [
// 'Chrome',
'ChromeHeadlessNoSandbox',
Expand Down Expand Up @@ -74,7 +67,7 @@ module.exports = config => {
},
...(process.env.TESTS_PATTERN || '*')
.split(' ')
.map(pattern => path.resolve(__dirname, `./tests/**/${pattern.trim()}.test.ts`)),
.map(pattern => path.resolve(__dirname, `./tests/**/${pattern.trim()}*.ts`)),
],

webpackMiddleware: {
Expand Down
19 changes: 10 additions & 9 deletions packages/connect/e2e/karma.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,26 @@ function CustomReporter(rootConfig, logger) {
log.info('Running @trezor/connect tests...');
log.info('FW:', process.env.TESTS_FIRMWARE);
log.info('Methods:', process.env.TESTS_INCLUDED_METHODS || 'All');
},

onSpecStart: (_browser, spec) => {
log.warn('onSpecStart', spec);
log.info('Pattern:', process.env.TESTS_PATTERN || '*');
},

onSpecComplete: (_browser, spec) => {
log.info(spec.success ? '✓' : '✖', spec.fullName);
if (!spec.success) {
log.info(spec);
if (spec.skipped) {
log.warn('○ skipped', spec.fullName);
} else if (spec.success) {
log.info('✓', spec.fullName);
} else {
log.error('✖', spec.fullName);
log.error(spec);
}
},

onRunComplete: () => {
log.warn('onRunComplete');
log.info('onRunComplete');
},

onExit: done => {
log.warn('onExit');
log.info('onExit');
done();
},
};
Expand Down
2 changes: 2 additions & 0 deletions packages/connect/e2e/karma.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ jasmine.getEnv().beforeAll(() => {
});
});

it.skip = xit;
it.only = fit;
// expect is missing "any" matcher
expect.any = jasmine.any;

Expand Down

0 comments on commit fb888be

Please sign in to comment.