Adjust tests for node:test env (#5509)

This commit is contained in:
Jaco
2023-02-25 11:48:26 +02:00
committed by GitHub
parent beb7b54e4a
commit a8d7566186
151 changed files with 674 additions and 950 deletions
+23 -18
View File
@@ -1,11 +1,14 @@
// Copyright 2017-2023 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import type { Registry } from '@polkadot/types/types';
import fs from 'fs';
import path from 'path';
import process from 'process';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { TypeDefInfo } from '@polkadot/types/types';
import { blake2AsHex } from '@polkadot/util-crypto';
@@ -86,24 +89,26 @@ describe('Abi', (): void => {
});
describe('TypeDef', (): void => {
it.each(Object.keys(abis))('initializes from a contract ABI: %s', (abiName): void => {
const abi = new Abi(abis[abiName]);
const json = stringifyJson(abi.registry);
const cmpFile = path.join(cmpPath, `${abiName}.test.json`);
const cmpText = fs.readFileSync(cmpFile, 'utf-8');
for (const [abiName, abiJson] of Object.entries(abis)) {
it(`initializes from a contract ABI: ${abiName}`, (): void => {
const abi = new Abi(abiJson);
const registryJson = stringifyJson(abi.registry);
const cmpFile = path.join(cmpPath, `${abiName}.test.json`);
const cmpText = fs.readFileSync(cmpFile, 'utf-8');
try {
expect(JSON.parse(json)).toEqual(JSON.parse(cmpText));
} catch (error) {
if (process.env.GITHUB_REPOSITORY) {
console.error(json);
try {
expect(JSON.parse(registryJson)).toEqual(JSON.parse(cmpText));
} catch (error) {
if (process.env.GITHUB_REPOSITORY) {
console.error(registryJson);
throw error;
throw error;
}
fs.writeFileSync(cmpFile, registryJson, { flag: 'w' });
}
fs.writeFileSync(cmpFile, json, { flag: 'w' });
}
});
});
}
});
it('has the correct hash for the source', (): void => {
@@ -1,6 +1,9 @@
// Copyright 2017-2023 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import { TypeRegistry } from '@polkadot/types';
import abis from '../test/contracts';
+6 -3
View File
@@ -1,9 +1,12 @@
// Copyright 2017-2023 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import fs from 'fs';
import path from 'path';
import process from 'process';
// eslint-disable-next-line spaced-comment
/// <reference types="@polkadot/dev/node/test/node" />
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { toPromiseMethod } from '@polkadot/api';