Skip to content

Commit 450bbcd

Browse files
authored
fix: refactoring broken tests (#688)
1 parent 8103891 commit 450bbcd

29 files changed

+399
-497
lines changed

.changeset/young-panthers-argue.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@fuel-ts/abi-typegen": patch
3+
"fuels": patch
4+
"@fuel-ts/versions": patch
5+
---
6+
7+
Refactoring and fixing broken tests

packages/abi-typegen/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
],
3434
"license": "Apache-2.0",
3535
"dependencies": {
36+
"@fuel-ts/versions": "workspace:*",
3637
"commander": "^9.4.1",
3738
"glob": "^8.0.3",
3839
"handlebars": "^4.7.7",
@@ -41,7 +42,6 @@
4142
"rimraf": "^3.0.2"
4243
},
4344
"devDependencies": {
44-
"@fuel-ts/versions": "workspace:*",
4545
"@types/glob": "^8.0.0",
4646
"@types/lodash.upperfirst": "^4.3.7",
4747
"@types/mkdirp": "^1.0.2",
@@ -52,8 +52,6 @@
5252
"transpile:hbs": "ts-node ./scripts/transpile.hbs.ts",
5353
"prebuild": "pnpm transpile:hbs",
5454
"build": "tsup --dts",
55-
"build:fixtures": "ts-node ./test/fixtures/buildAll.ts",
56-
"test": "jest test --coverage",
57-
"test:watch": "jest test --watch --coverage"
55+
"build:fixtures": "ts-node ./test/fixtures/buildAll.ts"
5856
}
5957
}

packages/abi-typegen/src/bin.test.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/fuels/package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
".": {
1515
"require": "./dist/index.js",
1616
"default": "./dist/index.mjs"
17-
},
18-
"./dist/cli": {
19-
"require": "./dist/dist.js",
20-
"default": "./dist/dist.mjs"
2117
}
2218
},
2319
"publishConfig": {
@@ -59,8 +55,6 @@
5955
},
6056
"scripts": {
6157
"build": "tsup --dts",
62-
"build:watch": "tsup --dts --watch",
63-
"test": "jest test --coverage",
64-
"test:watch": "jest test --watch --coverage"
58+
"build:watch": "tsup --dts --watch"
6559
}
6660
}

packages/fuels/src/bin.test.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/fuels/src/cli.test.ts

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
1-
// TODO: Review and fix tests
1+
import { versions } from '@fuel-ts/versions';
2+
import { Command } from 'commander';
23

3-
// import { Command } from 'commander';
4-
5-
// import { run } from './cli';
6-
7-
// jest.mock('@fuel-ts/versions', () => ({
8-
// versions: { FUELS: '9.8.7' },
9-
// }));
4+
import { run } from './cli';
105

116
describe('cli.js', () => {
127
test('should call `versions` sub-program', async () => {
13-
expect(true).toBeTruthy();
148
// mocking
15-
// const name = jest.spyOn(Command.prototype, 'name');
16-
// const version = jest.spyOn(Command.prototype, 'version');
17-
// const command = jest.spyOn(Command.prototype, 'command');
18-
// const description = jest.spyOn(Command.prototype, 'description');
19-
// const action = jest.spyOn(Command.prototype, 'action');
20-
// const parse = jest.spyOn(Command.prototype, 'parse').mockImplementation();
21-
22-
// // executing
23-
// run([]); // simulates argv array
24-
25-
// // validating
26-
// expect(name).toHaveBeenCalledWith('fuels');
27-
// expect(version).toHaveBeenCalledWith('9.8.7');
28-
29-
// expect(command).toHaveBeenNthCalledWith(1, 'versions');
30-
// expect(description).toHaveBeenNthCalledWith(1, 'check for version incompatibilities');
31-
32-
// expect(command).toHaveBeenNthCalledWith(2, 'typegen');
33-
// expect(description).toHaveBeenNthCalledWith(
34-
// 2,
35-
// 'generate typescript from contract abi json files'
36-
// );
37-
38-
// expect(action).toHaveBeenCalledTimes(2);
39-
// expect(parse).toHaveBeenCalledTimes(1);
9+
const name = jest.spyOn(Command.prototype, 'name');
10+
const version = jest.spyOn(Command.prototype, 'version');
11+
const command = jest.spyOn(Command.prototype, 'command');
12+
const description = jest.spyOn(Command.prototype, 'description');
13+
const action = jest.spyOn(Command.prototype, 'action');
14+
const parse = jest.spyOn(Command.prototype, 'parse').mockImplementation();
15+
16+
// executing
17+
const argv = ['a', 'b', 'c'];
18+
run(argv);
19+
20+
// validating
21+
expect(name).toHaveBeenCalledWith('fuels');
22+
expect(version).toHaveBeenCalledWith(versions.FUELS);
23+
24+
expect(command).toHaveBeenNthCalledWith(1, 'versions');
25+
expect(description).toHaveBeenNthCalledWith(1, 'check for version incompatibilities');
26+
27+
expect(command).toHaveBeenNthCalledWith(2, 'typegen');
28+
expect(description).toHaveBeenNthCalledWith(
29+
2,
30+
'generate typescript from contract abi json files'
31+
);
32+
33+
expect(action).toHaveBeenCalledTimes(2);
34+
expect(parse).toHaveBeenCalledTimes(1);
35+
expect(parse).toHaveBeenCalledWith(argv);
4036
});
4137
});

packages/fuels/src/cli.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { configureCliOptions as routeTypeGen } from '@fuel-ts/abi-typegen/cli';
1+
import { configureCliOptions as configureTypegenCliOptions } from '@fuel-ts/abi-typegen/cli';
22
import { versions } from '@fuel-ts/versions';
33
import { run as runVersions } from '@fuel-ts/versions/cli';
44
import { Command } from 'commander';
5-
import { argv } from 'process';
65

7-
export function run(_argv: string[]) {
6+
export function run(argv: string[]) {
87
const program = new Command();
8+
99
program.name('fuels');
1010
program.version(versions.FUELS);
1111

@@ -20,7 +20,7 @@ export function run(_argv: string[]) {
2020
.command('typegen')
2121
.description(`generate typescript from contract abi json files`);
2222

23-
routeTypeGen(typegen);
23+
configureTypegenCliOptions(typegen);
2424

2525
// vroom vroom
2626
program.parse(argv);

packages/versions/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,15 @@
2929
],
3030
"license": "Apache-2.0",
3131
"dependencies": {
32-
"@types/cli-table": "^0.3.1",
33-
"@types/yargs": "^17.0.13",
3432
"chalk": "4",
3533
"cli-table": "^0.3.11",
3634
"semver": "^7.3.8"
3735
},
3836
"devDependencies": {
37+
"@types/cli-table": "^0.3.1",
3938
"@types/semver": "^7.3.13"
4039
},
4140
"scripts": {
42-
"build": "tsup --dts --env.BUILD_VERSION $BUILD_VERSION --env.FORC_VERSION $FORC_VERSION --env.FUEL_CORE_VERSION $FUEL_CORE_VERSION",
43-
"test": "jest test --coverage",
44-
"test:watch": "jest test --watch --coverage"
41+
"build": "tsup --dts --env.BUILD_VERSION $BUILD_VERSION --env.FORC_VERSION $FORC_VERSION --env.FUEL_CORE_VERSION $FUEL_CORE_VERSION"
4542
}
4643
}

packages/versions/src/bin.test.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)