-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: add transforms fixtures for codemod test (#1421)
- @suspensive/react-query-5@3.0.0-next.4
- @suspensive/react-query-5@3.0.0-next.3
- @suspensive/react-query-5@3.0.0-next.2
- @suspensive/react-query-5@3.0.0-next.1
- @suspensive/react-query-5@3.0.0-next.0
- @suspensive/react-query-4@3.0.0-next.4
- @suspensive/react-query-4@3.0.0-next.3
- @suspensive/react-query-4@3.0.0-next.2
- @suspensive/react-query-4@3.0.0-next.1
- @suspensive/react-query-4@3.0.0-next.0
- @suspensive/react-query@3.0.0-next.4
- @suspensive/react-query@3.0.0-next.3
- @suspensive/react-query@3.0.0-next.2
- @suspensive/react-query@3.0.0-next.1
- @suspensive/react-query@3.0.0-next.0
- @suspensive/react@3.0.0-next.4
- @suspensive/react@3.0.0-next.3
- @suspensive/react@3.0.0-next.2
- @suspensive/react@3.0.0-next.1
- @suspensive/react@3.0.0-next.0
- @suspensive/jotai@3.0.0-next.4
- @suspensive/jotai@3.0.0-next.3
- @suspensive/jotai@3.0.0-next.2
- @suspensive/jotai@3.0.0-next.1
- @suspensive/jotai@3.0.0-next.0
Showing
8 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# transforms testfixtures | ||
packages/codemods/src/transforms/testfixtures/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
import { suspensiveTypeScriptConfig } from '@suspensive/eslint-config' | ||
|
||
export default [...suspensiveTypeScriptConfig] | ||
export default [ | ||
...suspensiveTypeScriptConfig, | ||
{ | ||
ignores: ['./src/transforms/testfixtures/**'], | ||
}, | ||
] |
2 changes: 2 additions & 0 deletions
2
...odemods/src/transforms/testfixtures/tanstack-query-import/tanstack-query-import.input.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { queryOptions } from "@suspensive/react-query"; | ||
export { queryOptions } |
2 changes: 2 additions & 0 deletions
2
...demods/src/transforms/testfixtures/tanstack-query-import/tanstack-query-import.output.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { queryOptions } from "@tanstack/react-query"; | ||
export { queryOptions } |
8 changes: 8 additions & 0 deletions
8
packages/codemods/src/transforms/tests/tanstack-query-import.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @ts-expect-error - type definitions not available | ||
import { defineInlineTest } from 'jscodeshift/dist/testUtils' | ||
import transform from '../tanstack-query-import' | ||
import { getTestfixtures } from '../utils/getTestfixtures' | ||
|
||
const { input, expectedOutput, testName } = getTestfixtures('tanstack-query-import', 'jsx') | ||
|
||
defineInlineTest(transform, null, input, expectedOutput, testName) |
60 changes: 60 additions & 0 deletions
60
packages/codemods/src/transforms/utils/getTestfixtures.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { readFileSync } from 'node:fs' | ||
import { join } from 'node:path' | ||
import type { Mock } from 'vitest' | ||
import { getTestfixtures } from './getTestfixtures' | ||
|
||
vi.mock('node:fs', () => ({ | ||
readFileSync: vi.fn(), | ||
})) | ||
|
||
const mockReadFileSync = readFileSync as Mock | ||
|
||
describe('getTestfixtures', () => { | ||
const mockInput = 'mock input content' | ||
const mockOutput = 'mock output content' | ||
const transformName = 'sampleTransform' | ||
const extension = 'js' | ||
const FIXTURE_DIR = join(__dirname, '../testfixtures', transformName) | ||
const inputPath = join(FIXTURE_DIR, `${transformName}.input.${extension}`) | ||
const outputPath = join(FIXTURE_DIR, `${transformName}.output.${extension}`) | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
it('should correctly read input and output fixture files', () => { | ||
mockReadFileSync.mockImplementation((filePath: string) => { | ||
if (filePath === inputPath) return mockInput | ||
if (filePath === outputPath) return mockOutput | ||
return '' | ||
}) | ||
|
||
const result = getTestfixtures(transformName, extension) | ||
|
||
expect(result).toEqual({ | ||
input: mockInput, | ||
expectedOutput: mockOutput, | ||
testName: transformName, | ||
}) | ||
expect(mockReadFileSync).toHaveBeenCalledWith(inputPath, 'utf8') | ||
expect(mockReadFileSync).toHaveBeenCalledWith(outputPath, 'utf8') | ||
}) | ||
|
||
it('should throw an error if input file is missing', () => { | ||
mockReadFileSync.mockImplementation((filePath: string) => { | ||
if (filePath === outputPath) return mockOutput | ||
throw new Error('File not found') | ||
}) | ||
|
||
expect(() => getTestfixtures(transformName, extension)).toThrow('File not found') | ||
}) | ||
|
||
it('should throw an error if output file is missing', () => { | ||
mockReadFileSync.mockImplementation((filePath: string) => { | ||
if (filePath === inputPath) return mockInput | ||
throw new Error('File not found') | ||
}) | ||
|
||
expect(() => getTestfixtures(transformName, extension)).toThrow('File not found') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { readFileSync } from 'node:fs' | ||
import { join } from 'node:path' | ||
|
||
export function getTestfixtures(transformName: string, extension: 'js' | 'jsx' | 'ts' | 'tsx' = 'js') { | ||
const FIXTURE_DIR = join(__dirname, '../testfixtures', transformName) | ||
const inputPath = join(FIXTURE_DIR, `${transformName}.input.${extension}`) | ||
const outputPath = join(FIXTURE_DIR, `${transformName}.output.${extension}`) | ||
|
||
const input = readFileSync(inputPath, 'utf8').trim() | ||
const expectedOutput = readFileSync(outputPath, 'utf8').trim() | ||
|
||
return { | ||
input, | ||
expectedOutput, | ||
testName: transformName, | ||
} | ||
} |