Skip to content

Commit

Permalink
feat: Change tools mocha + nyc -> jest
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyu1225 authored and mordochi committed Jan 8, 2024
1 parent b617c16 commit ad42571
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 429 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.coverage


# nyc test coverage
.nyc_output
Expand Down
12 changes: 12 additions & 0 deletions packages/dappauth/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: true,
},
},
],
],
};
10 changes: 4 additions & 6 deletions packages/dappauth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
},
"scripts": {
"build": "rollup -c",
"test": "npm run lint && nyc mocha test/*",
"prettier:watch": "onchange '**/*.js' -- prettier --write {{changed}}",
"lint": "eslint --ext .js src/",
"coverage": "nyc report --reporter=text-lcov | coveralls"
"test": "jest --config=./test/unit/jest.config.cjs --coverage=true --coverage-reporters=text",
"prettier:watch": "onchange '**/*.js' -- prettier --write {{changed}}"
},
"author": "Pazams <[email protected]>",
"license": "MIT",
Expand All @@ -39,14 +38,13 @@
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-node-resolve": "^15.2.1",
"babel-eslint": "^8.0.1",
"babel-jest": "^29.7.0",
"babel-plugin-istanbul": "^6.1.1",
"coveralls": "^3.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.0",
"mocha": "^10.2.0",
"mocha-lcov-reporter": "^1.3.0",
"nyc": "^15.1.0",
"jest": "^29.7.0",
"onchange": "^7.1.0",
"prettier": "^1.14.3",
"rollup": "^3.29.1",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { privateToPublic, stripHexPrefix } from 'ethereumjs-util';
import { equal } from 'assert';
import DappAuth from '../src/index.js';
import { removeHexPrefix } from '../src/utils/index.js';
import DappAuth from '../../src/index.js';
import { removeHexPrefix } from '../../src/utils/index.js';
import ProviderMock from './provider-mock.js';
import ContractMock from './contract-mock.js';
import { generateRandomKey, keyToAddress, signEOAPersonalMessage, signERC1654PersonalMessage } from './test-utils.js';
Expand Down
51 changes: 51 additions & 0 deletions packages/dappauth/test/unit/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module.exports = {
preset: 'ts-jest',
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
rootDir: '../..',
transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
verbose: false,
/**
* restoreMocks [boolean]
*
* Default: false
*
* Automatically restore mock state between every test.
* Equivalent to calling jest.restoreAllMocks() between each test.
* This will lead to any mocks having their fake implementations removed
* and restores their initial implementation.
*/
restoreMocks: true,
/**
* resetModules [boolean]
*
* Default: false
*
* By default, each test file gets its own independent module registry.
* Enabling resetModules goes a step further and resets the module registry before running each individual test.
* This is useful to isolate modules for every test so that local module state doesn't conflict between tests.
* This can be done programmatically using jest.resetModules().
*/
resetModules: true,
testMatch: ['<rootDir>/test/unit/**/*.(spec|test).(js|ts)'],
coverageDirectory: '../../.coverage/unit',
collectCoverageFrom: ['src/**'],
collectCoverage: true,
coverageReporters: [
[
'json',
{
file: 'dappauth-unit-coverage.json',
},
],
],
};
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ad42571

Please sign in to comment.