Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests #10

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/fixes/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ export function fixReferences(contents, options = {}) {
const removeAll = !options.types || options.types === 'all';
const find = removeAll ? `/ <reference types=` : `/ <reference types="${options.types}`;

const fixed = root
root
// @ts-expect-error
.find(j.Comment)
// @ts-expect-error
.filter((path) => path.value.value.startsWith(find))
// @ts-expect-error
.forEach((path) => j(path).remove())
.toSource();
.forEach((path) => j(path).remove());

return fixed;
return root.toSource();
}
62 changes: 62 additions & 0 deletions src/fixes/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,66 @@ describe('fixReferences', () => {

expect(result).toBe(`export const two = 2;`);
});

describe('https://github.com/machty/ember-concurrency/issues/564', () => {
test('declarations/helpers/cancel-all.d.ts', () => {
let code = stripIndent`
/// <reference types="ember-source/types/preview/@ember/component/-private/signature-utils" />
/// <reference types="ember-source/types/preview/@ember/component/helper" />
import type { Task } from '../index';
type CancelAllParams = [task: Task<any, any[]>];
export declare function cancelHelper(args: CancelAllParams): (...innerArgs: any[]) => any;
declare const _default: import("@ember/component/helper").FunctionBasedHelper<{
Args: {
Positional: CancelAllParams;
Named: import("@ember/component/helper").EmptyObject;
};
Return: (...innerArgs: any[]) => any;
}>;
export default _default;
`;

let result = fixReferences(code);

expect(result).toMatchInlineSnapshot(`
"import type { Task } from '../index';
type CancelAllParams = [task: Task<any, any[]>];
export declare function cancelHelper(args: CancelAllParams): (...innerArgs: any[]) => any;
declare const _default: import("@ember/component/helper").FunctionBasedHelper<{
Args: {
Positional: CancelAllParams;
Named: import("@ember/component/helper").EmptyObject;
};
Return: (...innerArgs: any[]) => any;
}>;
export default _default;"
`);
});

test('declarations/-private/ember-environment.d.ts', () => {
let code = stripIndent`
export declare class EmberEnvironment extends Environment {
assert(...args: any[]): void;
reportUncaughtRejection(error: any): void;
defer(): any;
globalDebuggingEnabled(): any;
}
export declare const EMBER_ENVIRONMENT: EmberEnvironment;
import { Environment } from './external/environment';
`;

let result = fixReferences(code);

expect(result).toMatchInlineSnapshot(`
"export declare class EmberEnvironment extends Environment {
assert(...args: any[]): void;
reportUncaughtRejection(error: any): void;
defer(): any;
globalDebuggingEnabled(): any;
}
export declare const EMBER_ENVIRONMENT: EmberEnvironment;
import { Environment } from './external/environment';"
`);
});
});
});
9 changes: 8 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ describe('fixBadDeclarationOutput', () => {
/// <reference types="@glint/whatever/module">
/// <reference types="node_modules/@glint/whatever2/module">
/// <reference types="xyz">

export declare const two: number;
export declare const three: string;
export declare const four: 'literal';
`
);

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

let aContents = await read(a);

expect(aContents).toBe(`export declare const two: number;`);
expect(aContents).toMatchInlineSnapshot(`
"export declare const two: number;
export declare const three: string;
export declare const four: 'literal';"
`);
});
});
Loading