Skip to content

Commit

Permalink
feat: add jest-github-reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
AbigailDeng authored and AbigailDeng committed Apr 13, 2023
1 parent dadfc99 commit 1d00e7a
Show file tree
Hide file tree
Showing 6 changed files with 442 additions and 19 deletions.
5 changes: 3 additions & 2 deletions jest.browser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
collectCoverageFrom: [
'**/src/**/*.js',
'!**/src/types/*.js',
'!**/src/scrpt-polyfill.js',
'!**/node_modules/**',
'!**/examples/**',
'!**/dist/**',
Expand Down Expand Up @@ -111,7 +112,7 @@ module.exports = {
// projects: null,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
reporters: ['default', 'jest-github-reporter'],

// Automatically reset mock state between every test
// resetMocks: false,
Expand Down Expand Up @@ -156,7 +157,7 @@ module.exports = {

// The glob patterns Jest uses to detect test files
testMatch: [
"**/test/unit/**/?(*.)+(test).[jt]s?(x)",
'**/test/unit/**/?(*.)+(test).[jt]s?(x)',
// "**/?(*.)+(spec|test).[tj]s?(x)"
],

Expand Down
15 changes: 7 additions & 8 deletions jest.node.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {

collectCoverageFrom: [
'**/src/**/*.js',
'!**/src/scrpt-polyfill.js',
'!**/src/types/*.js',
'!**/node_modules/**',
'!**/examples/**',
Expand Down Expand Up @@ -74,9 +75,7 @@ module.exports = {
// globals: {},

// An array of directory names to be searched recursively up from the requiring module's location
moduleDirectories: [
"node_modules"
],
moduleDirectories: ['node_modules'],

// An array of file extensions your modules use
// moduleFileExtensions: [
Expand All @@ -90,7 +89,7 @@ module.exports = {

// A map from regular expressions to module names that allow to stub out resources with a single module
moduleNameMapper: {
'^scryptsy$': path.resolve('src/scrypt-polyfill.js')
'^scryptsy$': path.resolve('src/scrypt-polyfill.js'),
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
Expand All @@ -109,7 +108,7 @@ module.exports = {
// projects: null,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
reporters: ['default', 'jest-github-reporter'],

// Automatically reset mock state between every test
// resetMocks: false,
Expand Down Expand Up @@ -154,7 +153,7 @@ module.exports = {

// The glob patterns Jest uses to detect test files
testMatch: [
"**/test/unit/**/?(*.)+(test).[jt]s?(x)",
'**/test/unit/**/?(*.)+(test).[jt]s?(x)',
// "**/?(*.)+(spec|test).[tj]s?(x)"
],

Expand All @@ -180,8 +179,8 @@ module.exports = {

// A map from regular expressions to paths to transformers
transform: {
'^.+\\.js?$': 'babel-jest'
}
'^.+\\.js?$': 'babel-jest',
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"jest": "^29.4.1",
"jest-environment-jsdom": "^29.4.3",
"jest-environment-jsdom-fifteen": "^1.0.2",
"jest-github-reporter": "^1.1.1",
"lint-staged": "^9.0.2",
"rimraf": "^2.6.3",
"size-limit": "^8.1.2",
Expand Down
20 changes: 13 additions & 7 deletions test/unit/chain/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ describe('chain should work', () => {
chain.getContractFileDescriptorSet = jest.fn(() => {
return {
file: [],
}
};
});
expect(() => chain.contractAt(address, null, ...args)).toThrow('no such contract');
expect(() => chain.contractAt(address, null, ...args)).toThrow(
'no such contract'
);
});
test('test is concrete contract when async', async () => {
const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint));
Expand All @@ -71,9 +73,9 @@ describe('chain should work', () => {
isSync: false,
};
});
await chain.contractAt(address,null);
await chain.contractAt(address, null);
expect(error).toEqual(new Error('no such contract'));
},5000);
}, 5000);
test('test is invalid contract with noop callback', async () => {
const address =
'ELF_iUY5CLwzU8L8vjVgH95vx3ZRuvD5d9hVK3EdPMVD8v9EaQT75_AELF';
Expand All @@ -82,13 +84,17 @@ describe('chain should work', () => {
file: [],
});
});
await expect(chain.contractAt(address, null)).rejects.toEqual(new Error('no such contract'));
await expect(chain.contractAt(address, null)).rejects.toEqual(
new Error('no such contract')
);
}, 5000);
test('test txId has corresponding transaction in the block with height when sync', async () => {
const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint));
const blockInfo = await aelf.chain.getBlockByHeight(1, true);
const txId = blockInfo.Body.Transactions[0];
const result = Array.isArray(aelf.chain.getMerklePath(txId,1,{ sync: true }));
const result = Array.isArray(
aelf.chain.getMerklePath(txId, 1, { sync: true })
);
expect(result).toBe(true);
}, 5000);
test('test txId has no corresponding transaction in the block with height when sync', async () => {
Expand All @@ -108,7 +114,7 @@ describe('chain should work', () => {
const txId = blockInfo.Body.Transactions[0];
const result = await aelf.chain.getMerklePath(txId, 1);
expect(Array.isArray(result)).toBe(true);
}, 5000);
}, 10000);
test('test txId has no corresponding transaction in the block with height when async', async () => {
const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint));
const blockInfo = await aelf.chain.getBlockByHeight(1, true);
Expand Down
20 changes: 20 additions & 0 deletions test/unit/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import AElf from '../../src/index';
const stageEndpoint = 'https://explorer-test-tdvw.aelf.io/chain';
describe('test AElf', () => {
test('test AElf is connected', () => {
const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint));
const result = aelf.isConnected();
expect(result).toBeTruthy();
});
// test('test AElf reset',() => {
// const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint));
// aelf.reset();
// });
test('test AElf set provider', () => {
const aelf = new AElf(
new AElf.providers.HttpProvider('https://aelf-public-node.aelf.io')
);
aelf.setProvider(new AElf.providers.HttpProvider(stageEndpoint));
expect(aelf.currentProvider.host).toEqual(stageEndpoint);
});
});
Loading

0 comments on commit 1d00e7a

Please sign in to comment.