Remove __dirname usages in tests (#5492)

This commit is contained in:
Jaco
2023-02-17 08:20:29 +02:00
committed by GitHub
parent cc1d51a6ca
commit ea45c7e689
2 changed files with 21 additions and 17 deletions
+18 -16
View File
@@ -5,6 +5,7 @@ import type { Registry } from '@polkadot/types/types';
import fs from 'fs';
import path from 'path';
import process from 'process';
import { TypeDefInfo } from '@polkadot/types/types';
import { blake2AsHex } from '@polkadot/util-crypto';
@@ -41,6 +42,9 @@ interface JSONAbi {
}
}
// FIXME When Jest is removed with ESM tests, this should be converted to use import.meta.url
const cmpPath = path.join(process.cwd(), 'packages/api-contract/src/test/compare');
function stringifyInfo (key: string, value: unknown): unknown {
return key === 'info'
? TypeDefInfo[value as number]
@@ -82,25 +86,23 @@ describe('Abi', (): void => {
});
describe('TypeDef', (): void => {
Object.keys(abis).forEach((abiName) => {
it(`initializes from a contract ABI (${abiName})`, (): void => {
const abi = new Abi(abis[abiName]);
const json = stringifyJson(abi.registry);
const cmpPath = path.join(__dirname, `../test/compare/${abiName}.test.json`);
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');
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
expect(JSON.parse(json)).toEqual(require(cmpPath));
} catch (error) {
if (process.env.GITHUB_REPOSITORY) {
console.error(json);
try {
expect(JSON.parse(json)).toEqual(JSON.parse(cmpText));
} catch (error) {
if (process.env.GITHUB_REPOSITORY) {
console.error(json);
throw error;
}
fs.writeFileSync(cmpPath, json, { flag: 'w' });
throw error;
}
});
fs.writeFileSync(cmpFile, json, { flag: 'w' });
}
});
});
+3 -1
View File
@@ -3,6 +3,7 @@
import fs from 'fs';
import path from 'path';
import process from 'process';
import { toPromiseMethod } from '@polkadot/api';
@@ -12,7 +13,8 @@ import v1contractFlipper from '../test/contracts/ink/v1/flipper.contract.json' a
import { Code } from './Code';
import { mockApi } from './mock';
const v0wasmFlipper = fs.readFileSync(path.join(__dirname, '../test/contracts/ink/v0/flipper.wasm'));
// FIXME When Jest is removed with ESM tests, this should be converted to use import.meta.url
const v0wasmFlipper = fs.readFileSync(path.join(process.cwd(), 'packages/api-contract/src/test/contracts/ink/v0/flipper.wasm'), 'utf-8');
describe('Code', (): void => {
it('can construct with an individual ABI/WASM combo', (): void => {