Skip to content

Commit

Permalink
infra: ts-check tests (#1065)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Apr 4, 2024
1 parent db78a35 commit ec6c867
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
60 changes: 42 additions & 18 deletions test/sqlMigration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ describe('sqlMigration', () => {
const content = 'SELECT 1 FROM something';
const { up, down } = getActions(content);

expect(up).toBeDefined();
expect(down).toBeFalsy();
expect(up).toBeTypeOf('function');
expect(down).toBe(false);

const sql = vi.fn();

expect(up({ sql })).not.toBeDefined();
expect(
// @ts-expect-error: simplified for testing
up({ sql })
).not.toBeDefined();
expect(sql).toHaveBeenCalled();
expect(sql).toHaveBeenLastCalledWith(content.trim());
});
Expand All @@ -24,12 +27,15 @@ SELECT 1 FROM something
`;
const { up, down } = getActions(content);

expect(up).toBeDefined();
expect(down).toBeFalsy();
expect(up).toBeTypeOf('function');
expect(down).toBe(false);

const sql = vi.fn();

expect(up({ sql })).not.toBeDefined();
expect(
// @ts-expect-error: simplified for testing
up({ sql })
).not.toBeDefined();
expect(sql).toHaveBeenCalled();
expect(sql).toHaveBeenLastCalledWith(content);
});
Expand All @@ -47,18 +53,24 @@ SELECT 2 FROM something

const { up, down } = getActions(content);

expect(up).toBeDefined();
expect(down).toBeDefined();
expect(up).toBeTypeOf('function');
expect(down).toBeTypeOf('function');

const upSql = vi.fn();

expect(up({ sql: upSql })).not.toBeDefined();
expect(
// @ts-expect-error: simplified for testing
up({ sql: upSql })
).not.toBeDefined();
expect(upSql).toHaveBeenCalled();
expect(upSql).toHaveBeenLastCalledWith(upMigration);

const downSql = vi.fn();

expect(down({ sql: downSql })).not.toBeDefined();
expect(
// @ts-expect-error: simplified for testing
down({ sql: downSql })
).not.toBeDefined();
expect(downSql).toHaveBeenCalled();
expect(downSql).toHaveBeenLastCalledWith(downMigration);
});
Expand All @@ -76,18 +88,24 @@ SELECT 2 FROM something

const { up, down } = getActions(content);

expect(up).toBeDefined();
expect(down).toBeDefined();
expect(up).toBeTypeOf('function');
expect(down).toBeTypeOf('function');

const upSql = vi.fn();

expect(up({ sql: upSql })).not.toBeDefined();
expect(
// @ts-expect-error: simplified for testing
up({ sql: upSql })
).not.toBeDefined();
expect(upSql).toHaveBeenCalled();
expect(upSql).toHaveBeenLastCalledWith(upMigration);

const downSql = vi.fn();

expect(down({ sql: downSql })).not.toBeDefined();
expect(
// @ts-expect-error: simplified for testing
down({ sql: downSql })
).not.toBeDefined();
expect(downSql).toHaveBeenCalled();
expect(downSql).toHaveBeenLastCalledWith(downMigration);
});
Expand All @@ -105,18 +123,24 @@ SELECT 2 FROM something

const { up, down } = getActions(content);

expect(up).toBeDefined();
expect(down).toBeDefined();
expect(up).toBeTypeOf('function');
expect(down).toBeTypeOf('function');

const upSql = vi.fn();

expect(up({ sql: upSql })).not.toBeDefined();
expect(
// @ts-expect-error: simplified for testing
up({ sql: upSql })
).not.toBeDefined();
expect(upSql).toHaveBeenCalled();
expect(upSql).toHaveBeenLastCalledWith(upMigration);

const downSql = vi.fn();

expect(down({ sql: downSql })).not.toBeDefined();
expect(
// @ts-expect-error: simplified for testing
down({ sql: downSql })
).not.toBeDefined();
expect(downSql).toHaveBeenCalled();
expect(downSql).toHaveBeenLastCalledWith(downMigration);
});
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"compilerOptions": {
"target": "ES2019",
"target": "ES2020",
"module": "CommonJS",
"moduleResolution": "Node",
"lib": ["ES2019", "DOM"],
"lib": ["ES2020", "DOM"],
"noEmit": true,
"esModuleInterop": true,
"sourceMap": false,
Expand All @@ -14,5 +14,5 @@
"noImplicitOverride": true,
"skipLibCheck": true
},
"exclude": ["node_modules", "templates", "test", "dist", "bin", "migrations"]
"exclude": ["node_modules", "templates", "dist", "bin", "migrations"]
}
4 changes: 2 additions & 2 deletions tsconfig.lint.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"compilerOptions": {
"target": "ES2019",
"target": "ES2020",
"moduleResolution": "Node",
"module": "CommonJS",
"strict": true,
"noEmit": true,
"lib": ["ES2019"],
"lib": ["ES2020"],
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": true,
Expand Down

0 comments on commit ec6c867

Please sign in to comment.