Skip to content

Commit fbb8bfd

Browse files
Merge pull request #10 from NullVoxPopuli/be-more-robust
Add more tests
2 parents 56c1b08 + 5468ab9 commit fbb8bfd

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

src/fixes/typescript.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ export function fixReferences(contents, options = {}) {
1111
const removeAll = !options.types || options.types === 'all';
1212
const find = removeAll ? `/ <reference types=` : `/ <reference types="${options.types}`;
1313

14-
const fixed = root
14+
root
1515
// @ts-expect-error
1616
.find(j.Comment)
1717
// @ts-expect-error
1818
.filter((path) => path.value.value.startsWith(find))
1919
// @ts-expect-error
20-
.forEach((path) => j(path).remove())
21-
.toSource();
20+
.forEach((path) => j(path).remove());
2221

23-
return fixed;
22+
return root.toSource();
2423
}

src/fixes/typescript.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,66 @@ describe('fixReferences', () => {
7676

7777
expect(result).toBe(`export const two = 2;`);
7878
});
79+
80+
describe('https://github.com/machty/ember-concurrency/issues/564', () => {
81+
test('declarations/helpers/cancel-all.d.ts', () => {
82+
let code = stripIndent`
83+
/// <reference types="ember-source/types/preview/@ember/component/-private/signature-utils" />
84+
/// <reference types="ember-source/types/preview/@ember/component/helper" />
85+
import type { Task } from '../index';
86+
type CancelAllParams = [task: Task<any, any[]>];
87+
export declare function cancelHelper(args: CancelAllParams): (...innerArgs: any[]) => any;
88+
declare const _default: import("@ember/component/helper").FunctionBasedHelper<{
89+
Args: {
90+
Positional: CancelAllParams;
91+
Named: import("@ember/component/helper").EmptyObject;
92+
};
93+
Return: (...innerArgs: any[]) => any;
94+
}>;
95+
export default _default;
96+
`;
97+
98+
let result = fixReferences(code);
99+
100+
expect(result).toMatchInlineSnapshot(`
101+
"import type { Task } from '../index';
102+
type CancelAllParams = [task: Task<any, any[]>];
103+
export declare function cancelHelper(args: CancelAllParams): (...innerArgs: any[]) => any;
104+
declare const _default: import("@ember/component/helper").FunctionBasedHelper<{
105+
Args: {
106+
Positional: CancelAllParams;
107+
Named: import("@ember/component/helper").EmptyObject;
108+
};
109+
Return: (...innerArgs: any[]) => any;
110+
}>;
111+
export default _default;"
112+
`);
113+
});
114+
115+
test('declarations/-private/ember-environment.d.ts', () => {
116+
let code = stripIndent`
117+
export declare class EmberEnvironment extends Environment {
118+
assert(...args: any[]): void;
119+
reportUncaughtRejection(error: any): void;
120+
defer(): any;
121+
globalDebuggingEnabled(): any;
122+
}
123+
export declare const EMBER_ENVIRONMENT: EmberEnvironment;
124+
import { Environment } from './external/environment';
125+
`;
126+
127+
let result = fixReferences(code);
128+
129+
expect(result).toMatchInlineSnapshot(`
130+
"export declare class EmberEnvironment extends Environment {
131+
assert(...args: any[]): void;
132+
reportUncaughtRejection(error: any): void;
133+
defer(): any;
134+
globalDebuggingEnabled(): any;
135+
}
136+
export declare const EMBER_ENVIRONMENT: EmberEnvironment;
137+
import { Environment } from './external/environment';"
138+
`);
139+
});
140+
});
79141
});

src/index.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ describe('fixBadDeclarationOutput', () => {
3939
/// <reference types="@glint/whatever/module">
4040
/// <reference types="node_modules/@glint/whatever2/module">
4141
/// <reference types="xyz">
42+
4243
export declare const two: number;
44+
export declare const three: string;
45+
export declare const four: 'literal';
4346
`
4447
);
4548

@@ -49,6 +52,10 @@ describe('fixBadDeclarationOutput', () => {
4952

5053
let aContents = await read(a);
5154

52-
expect(aContents).toBe(`export declare const two: number;`);
55+
expect(aContents).toMatchInlineSnapshot(`
56+
"export declare const two: number;
57+
export declare const three: string;
58+
export declare const four: 'literal';"
59+
`);
5360
});
5461
});

0 commit comments

Comments
 (0)