-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from ssssota/unexpected-skip-test
Unexpected skip test
- Loading branch information
Showing
5 changed files
with
166 additions
and
8 deletions.
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,5 @@ | ||
--- | ||
"vite-plugin-doctest": patch | ||
--- | ||
|
||
Fix unexpected skip testing |
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
154 changes: 154 additions & 0 deletions
154
packages/vite-plugin-doctest/src/transformers/typescript.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,154 @@ | ||
import { expect, it } from "vitest"; | ||
import { transform } from "./typescript"; | ||
const getCode = (maybeCode: string | { code: string }) => | ||
typeof maybeCode === "string" ? maybeCode : maybeCode.code; | ||
it("should generate test code", () => { | ||
expect( | ||
getCode( | ||
transform( | ||
` | ||
/** | ||
* @example | ||
* \`\`\`ts @import.meta.vitest | ||
* expect(add(1, 2)).toBe(3); | ||
* \`\`\` | ||
*/ | ||
export const add = (a: number, b: number) => a + b;`, | ||
"add.ts", | ||
), | ||
), | ||
).toMatchInlineSnapshot(` | ||
" | ||
/** | ||
* @example | ||
* \`\`\`ts @import.meta.vitest | ||
* expect(add(1, 2)).toBe(3); | ||
* \`\`\` | ||
*/ | ||
export const add = (a: number, b: number) => a + b; | ||
if (import.meta.vitest) { | ||
const {assert,chai,createExpect,expect,getRunningMode,isWatchMode,should,vi,vitest} = import.meta.vitest; | ||
import.meta.vitest.test("add.ts#0", async () => { | ||
expect(add(1, 2)).toBe(3); | ||
}); | ||
}" | ||
`); | ||
|
||
expect( | ||
getCode( | ||
transform( | ||
` | ||
/** | ||
* @example | ||
* \`\`\`ts @import.meta.vitest | ||
* const { add } = await import('./add'); | ||
* expect(add(1, 2)).toBe(3); | ||
* \`\`\` | ||
*/ | ||
export const sub = (a: number, b: number) => { | ||
/** | ||
* @example | ||
* \`\`\`ts @import.meta.vitest | ||
* expect(sub(1, 2)).toBe(-1); | ||
* \`\`\` | ||
*/ | ||
return a - b; | ||
};`, | ||
"sub.ts", | ||
), | ||
), | ||
).toMatchInlineSnapshot(` | ||
" | ||
/** | ||
* @example | ||
* \`\`\`ts @import.meta.vitest | ||
* const { add } = await import('./add'); | ||
* expect(add(1, 2)).toBe(3); | ||
* \`\`\` | ||
*/ | ||
export const sub = (a: number, b: number) => { | ||
/** | ||
* @example | ||
* \`\`\`ts @import.meta.vitest | ||
* expect(sub(1, 2)).toBe(-1); | ||
* \`\`\` | ||
*/ | ||
return a - b; | ||
}; | ||
if (import.meta.vitest) { | ||
const {assert,chai,createExpect,expect,getRunningMode,isWatchMode,should,vi,vitest} = import.meta.vitest; | ||
import.meta.vitest.test("sub.ts#0", async () => { | ||
const { add } = await import('./add'); | ||
expect(add(1, 2)).toBe(3); | ||
}); | ||
import.meta.vitest.test("sub.ts#1", async () => { | ||
expect(sub(1, 2)).toBe(-1); | ||
}); | ||
}" | ||
`); | ||
|
||
expect( | ||
getCode( | ||
transform( | ||
` | ||
/** | ||
* @example | ||
* \`\`\`ts @import.meta.vitest | ||
* const hoge = new Hoge(); | ||
* assert(hoge instanceof Hoge); | ||
* \`\`\` | ||
*/ | ||
class Hoge { | ||
internal = 1; | ||
/** | ||
* @example | ||
* \`\`\`ts @import.meta.vitest | ||
* const hoge = new Hoge(); | ||
* expect(hoge.add(1)).toBe(2); | ||
* expect(hoge.add(2)).toBe(4); | ||
* \`\`\` | ||
add(num) { | ||
return this.internal += num; | ||
} | ||
}`, | ||
"class.js", | ||
), | ||
), | ||
).toMatchInlineSnapshot(` | ||
" | ||
/** | ||
* @example | ||
* \`\`\`ts @import.meta.vitest | ||
* const hoge = new Hoge(); | ||
* assert(hoge instanceof Hoge); | ||
* \`\`\` | ||
*/ | ||
class Hoge { | ||
internal = 1; | ||
/** | ||
* @example | ||
* \`\`\`ts @import.meta.vitest | ||
* const hoge = new Hoge(); | ||
* expect(hoge.add(1)).toBe(2); | ||
* expect(hoge.add(2)).toBe(4); | ||
* \`\`\` | ||
add(num) { | ||
return this.internal += num; | ||
} | ||
} | ||
if (import.meta.vitest) { | ||
const {assert,chai,createExpect,expect,getRunningMode,isWatchMode,should,vi,vitest} = import.meta.vitest; | ||
import.meta.vitest.test("class.js#0", async () => { | ||
const hoge = new Hoge(); | ||
assert(hoge instanceof Hoge); | ||
}); | ||
import.meta.vitest.test("class.js#1", async () => { | ||
const hoge = new Hoge(); | ||
expect(hoge.add(1)).toBe(2); | ||
expect(hoge.add(2)).toBe(4); | ||
}); | ||
}" | ||
`); | ||
}); |
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