Skip to content

Commit c3fe8b4

Browse files
authored
chore: fix test types (#780)
1 parent 15e1020 commit c3fe8b4

5 files changed

Lines changed: 133 additions & 99 deletions

File tree

src/environment-full.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class FullEnvironment extends EnvironmentBase {
164164
* @param {string} generatorNamespace
165165
* @param {string[]} args
166166
*/
167-
async execute(generatorNamespace: string, arguments_ = []) {
167+
async execute(generatorNamespace: string, arguments_: string[] = []) {
168168
const namespace = requireNamespace(generatorNamespace);
169169
if (!(await this.get(namespace.namespace))) {
170170
await this.lookup({

test/command.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable @typescript-eslint/ban-ts-comment */
2-
// @ts-nocheck
31
import path, { dirname } from 'node:path';
42
import { fileURLToPath } from 'node:url';
53
import { beforeEach, describe, esmocha, expect, it } from 'esmocha';
@@ -15,6 +13,9 @@ type ParsedGenerator = {
1513
const __filename = fileURLToPath(import.meta.url);
1614
const __dirname = dirname(__filename);
1715

16+
const getRepository = (env: Environment) => (env as any).repository;
17+
const getComposedStore = (env: Environment) => (env as any).composedStore;
18+
1819
describe('environment (command)', () => {
1920
describe('#execute()', () => {
2021
let environment: Environment;
@@ -30,22 +31,22 @@ describe('environment (command)', () => {
3031
adapter.addAnswers({
3132
aproveInstall: false,
3233
});
33-
environment.repository.install = esmocha.fn().mockReturnValue(Promise.resolve([]));
34+
getRepository(environment).install = esmocha.fn().mockReturnValue(Promise.resolve([]));
3435
await expect(environment.execute('commands:options')).rejects.toThrow(
3536
/Installation of generator-commands is declined by the user. Install manually and try again/,
3637
);
37-
expect(environment.repository.install).not.toHaveBeenCalled();
38+
expect(getRepository(environment).install).not.toHaveBeenCalled();
3839
});
3940

4041
it('approving installation', async () => {
4142
adapter.addAnswers({
4243
aproveInstall: true,
4344
});
44-
environment.repository.install = esmocha.fn().mockReturnValue(Promise.resolve([]));
45+
getRepository(environment).install = esmocha.fn().mockReturnValue(Promise.resolve([]));
4546
await expect(environment.execute('commands:options')).rejects.toThrow(
4647
/You don't seem to have a generator with the name generator-commands installed./,
4748
);
48-
expect(environment.repository.install).toHaveBeenCalledWith(['generator-commands']);
49+
expect(getRepository(environment).install).toHaveBeenCalledWith(['generator-commands']);
4950
});
5051
});
5152
});
@@ -55,7 +56,7 @@ describe('environment (command)', () => {
5556

5657
beforeEach(async () => {
5758
environment = new Environment({ skipInstall: true, dryRun: true });
58-
environment.adapter.log = esmocha.fn();
59+
environment.adapter.log = esmocha.fn() as any;
5960
await environment.register(path.join(__dirname, 'fixtures/generator-commands/generators/options'));
6061
});
6162

@@ -64,7 +65,7 @@ describe('environment (command)', () => {
6465
let generator: ParsedGenerator;
6566
beforeEach(async () => {
6667
await environment.execute('commands:options');
67-
const generators = Object.values(environment.composedStore.getGenerators()) as ParsedGenerator[];
68+
const generators = Object.values(getComposedStore(environment).getGenerators()) as ParsedGenerator[];
6869
expect(generators.length).toEqual(1);
6970
generator = generators[0];
7071
});
@@ -90,7 +91,7 @@ describe('environment (command)', () => {
9091
'newValue',
9192
]);
9293

93-
const generators = Object.values(environment.composedStore.getGenerators()) as ParsedGenerator[];
94+
const generators = Object.values(getComposedStore(environment).getGenerators()) as ParsedGenerator[];
9495
expect(generators.length).toEqual(1);
9596
generator = generators[0];
9697
});
@@ -108,7 +109,7 @@ describe('environment (command)', () => {
108109
let generator: ParsedGenerator;
109110
beforeEach(async () => {
110111
await environment.execute('commands:options', ['-b', '-s', 'customValue']);
111-
const generators = Object.values(environment.composedStore.getGenerators()) as ParsedGenerator[];
112+
const generators = Object.values(getComposedStore(environment).getGenerators()) as ParsedGenerator[];
112113
expect(generators.length).toEqual(1);
113114
generator = generators[0];
114115
});
@@ -126,7 +127,7 @@ describe('environment (command)', () => {
126127

127128
beforeEach(() => {
128129
environment = new Environment({ skipInstall: true, dryRun: true });
129-
environment.adapter.log = esmocha.fn();
130+
environment.adapter.log = esmocha.fn() as any;
130131
environment.register(path.join(__dirname, 'fixtures/generator-commands/generators/arguments'));
131132
});
132133

@@ -135,7 +136,7 @@ describe('environment (command)', () => {
135136
let generator: ParsedGenerator;
136137
beforeEach(async () => {
137138
await environment.execute('commands:arguments');
138-
const generators = Object.values(environment.composedStore.getGenerators()) as ParsedGenerator[];
139+
const generators = Object.values(getComposedStore(environment).getGenerators()) as ParsedGenerator[];
139140
expect(generators.length).toEqual(1);
140141
generator = generators[0];
141142
});
@@ -149,7 +150,7 @@ describe('environment (command)', () => {
149150
let generator: ParsedGenerator;
150151
beforeEach(async () => {
151152
await environment.execute('commands:arguments', ['foo']);
152-
const generators = Object.values(environment.composedStore.getGenerators()) as ParsedGenerator[];
153+
const generators = Object.values(getComposedStore(environment).getGenerators()) as ParsedGenerator[];
153154
expect(generators.length).toEqual(1);
154155
generator = generators[0];
155156
});
@@ -177,8 +178,8 @@ describe('environment (command)', () => {
177178
});
178179
await command.parseAsync(['node', 'yo', 'bar']);
179180

180-
environment = command.env;
181-
const generators = Object.values(environment.composedStore.getGenerators()) as ParsedGenerator[];
181+
environment = command.env as Environment;
182+
const generators = Object.values(getComposedStore(environment).getGenerators()) as ParsedGenerator[];
182183
expect(generators.length).toEqual(1);
183184
generator = generators[0];
184185
});
@@ -208,8 +209,8 @@ describe('environment (command)', () => {
208209
'newValue',
209210
]);
210211

211-
environment = command.env;
212-
const generators = Object.values(environment.composedStore.getGenerators()) as ParsedGenerator[];
212+
environment = command.env as Environment;
213+
const generators = Object.values(getComposedStore(environment).getGenerators()) as ParsedGenerator[];
213214
expect(generators.length).toEqual(1);
214215
generator = generators[0];
215216
});

0 commit comments

Comments
 (0)