Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arhtudormorar committed Apr 15, 2024
1 parent bca0d6d commit 080a577
Show file tree
Hide file tree
Showing 7 changed files with 1,133 additions and 159 deletions.
21 changes: 21 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
},
"modules": "commonjs"
}
],
"@babel/preset-typescript",
"@babel/preset-react"
],
"env": {
"test": {
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}
}
}

26 changes: 24 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,39 @@ module.exports = {
testEnvironment: 'jsdom',
testTimeout: 10000,
moduleDirectories: ['node_modules', 'src'],
modulePaths: ['<rootDir>/src'],
roots: ['<rootDir>/src'],
transform: {
'^.+\\.[t|j]sx?$': 'ts-jest',
'^.+\\.(ts|js|tsx|jsx)$': ['@swc/jest'],
'^.+\\.scss$': 'jest-scss-transform',
'^.+\\.svg$': '<rootDir>/config/svgTransform.js'
},
transformIgnorePatterns: ['node_modules/(^.+\\\\.(ts|js|tsx|jsx)$)'],
testMatch: [
'**/__tests__/**/*.[jt]s?(x)',
'**/?(*.)+(spec|test|bgTest).[jt]s?(x)'
],
moduleNameMapper: {
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
'identity-obj-proxy',
uint8arrays: '<rootDir>/node_modules/uint8arrays/cjs/src',
multiformats: '<rootDir>/node_modules/multiformats/cjs/src'
},
setupFilesAfterEnv: ['<rootDir>/src/setupTests.js']
setupFilesAfterEnv: ['<rootDir>/src/setupTests.js'],
moduleFileExtensions: [
// Place tsx and ts to beginning as suggestion from Jest team
// https://jestjs.io/docs/configuration#modulefileextensions-arraystring
'tsx',
'ts',
'web.js',
'js',
'web.ts',
'web.tsx',
'json',
'node'
],
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname'
]
};
23 changes: 16 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@
"lint": "eslint --fix --ext js,ts,tsx src"
},
"devDependencies": {
"@babel/core": "7.20.5",
"@multiversx/sdk-core": ">= 12.18.0",
"@babel/core": "7.21.8",
"@babel/plugin-proposal-private-property-in-object": "7.21.11",
"@babel/plugin-transform-modules-commonjs": "7.23.3",
"@babel/preset-env": "7.24.0",
"@babel/preset-react": "7.23.3",
"@babel/preset-typescript": "7.23.3",
"@ledgerhq/hw-transport-mocker": "6.27.17",
"@multiversx/sdk-core": ">= 12.18.0",
"@octokit/rest": "19.0.5",
"@storybook/addon-actions": "6.5.14",
"@storybook/addon-essentials": "6.5.14",
Expand All @@ -45,6 +50,9 @@
"@storybook/react": "6.5.14",
"@storybook/test-runner": "0.9.1",
"@storybook/testing-library": "0.0.13",
"@swc-node/jest": "1.6.6",
"@swc/core": "1.3.74",
"@swc/jest": "0.2.27",
"@testing-library/jest-dom": "5.16.2",
"@testing-library/react": "13.3.0",
"@types/lodash": "4.14.181",
Expand All @@ -60,6 +68,7 @@
"@typescript-eslint/parser": "5.14.0",
"axios": "1.6.5",
"axios-mock-adapter": "1.21.2",
"babel-jest": "29.7.0",
"babel-loader": "8.3.0",
"css-loader": "5.2.6",
"dotenv": "16.0.3",
Expand All @@ -86,7 +95,7 @@
"husky": "8.0.1",
"identity-obj-proxy": "3.0.0",
"isomorphic-fetch": "3.0.0",
"jest": "28.1.1",
"jest": "29.7.0",
"jest-environment-jsdom": "28.1.3",
"jest-mock": "29.3.1",
"jest-scss-transform": "1.0.3",
Expand All @@ -103,7 +112,6 @@
"sass-loader": "10.1.1",
"storybook-css-modules": "1.0.8",
"style-loader": "2.0.0",
"ts-jest": "28.0.7",
"typescript": "4.7.3"
},
"keywords": [
Expand All @@ -114,9 +122,9 @@
"transaction"
],
"peerDependencies": {
"@multiversx/sdk-core": ">= 12.18.0",
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8",
"@multiversx/sdk-core": ">= 12.18.0",
"axios": ">=1.6.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down Expand Up @@ -149,21 +157,22 @@
"dependencies": {
"@lifeomic/axios-fetch": "3.0.1",
"@metamask/providers": "16.0.0",
"@multiversx/sdk-dapp-utils": "0.0.1",
"@multiversx/sdk-extension-provider": "3.0.0",
"@multiversx/sdk-hw-provider": "6.4.0",
"@multiversx/sdk-metamask-provider": "0.0.5",
"@multiversx/sdk-native-auth-client": "1.0.7",
"@multiversx/sdk-opera-provider": "1.0.0-alpha.1",
"@multiversx/sdk-wallet": "4.2.0",
"@multiversx/sdk-wallet-connect-provider": "4.1.1",
"@multiversx/sdk-web-wallet-cross-window-provider": "0.0.34",
"@multiversx/sdk-web-wallet-cross-window-provider": "0.0.35",
"@multiversx/sdk-web-wallet-provider": "3.2.1",
"@multiversx/sdk-dapp-utils": "0.0.1",
"@multiversx/sdk-webview-provider": "0.0.6",
"@reduxjs/toolkit": "1.8.2",
"bignumber.js": "9.x",
"linkify-react": "4.0.2",
"linkifyjs": "4.0.2",
"lit": "3.1.2",
"lodash.debounce": "4.0.8",
"lodash.isequal": "4.5.0",
"lodash.omit": "4.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import { sleep } from 'utils/asyncActions';
import { ExtensionLoginButton } from '../';
import { checkIsLoggedInStore } from './helpers';

jest.mock('reduxStore/slices/loginInfoSlice', () => {
return {
__esModule: true, // <----- this __esModule: true is important
...jest.requireActual('reduxStore/slices/loginInfoSlice')
};
});

jest.mock('@multiversx/sdk-extension-provider', () => {
const { ExtensionProvider } = require('./mocks/mockExtensionProvider');
return {
Expand Down Expand Up @@ -55,6 +62,10 @@ describe('ExtensionLoginButton tests', () => {
mockWindowLocation();
});

afterEach(() => {
jest.clearAllMocks();
});

it('should perform simple login and redirect', async () => {
const methods = renderWithProvider({
children: <ExtensionLoginButton callbackRoute={CALLBACK_ROUTE} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import { LedgerLoginButton } from '../LedgerLoginButton';
import { checkIsLoggedInStore, ledgerLogin } from './helpers';
import { mockLedgerProvider } from './mocks';

jest.mock('reduxStore/slices/loginInfoSlice', () => {
return {
__esModule: true, // <----- this __esModule: true is important
...jest.requireActual('reduxStore/slices/loginInfoSlice')
};
});

const CALLBACK_ROUTE = '/dashboard';

const tokenLoginWithoutSignature = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import * as timestampModule from '../../../../utils/dateTime/getUnixTimestamp';
import { getTokenExpiration } from '../getTokenExpiration';

jest.mock('../../../../utils/dateTime/getUnixTimestamp', () => {
return {
__esModule: true,
...jest.requireActual('../../../../utils/dateTime/getUnixTimestamp')
};
});

// 1669712100 Tue Nov 29 2022 08:55:00 GMT+0000
// 2 minutes expiration time
const nativeAuthToken =
Expand Down
Loading

0 comments on commit 080a577

Please sign in to comment.