-
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.
feat: adding create auction to index file
- Loading branch information
1 parent
ef516bd
commit cf53f4d
Showing
3 changed files
with
77 additions
and
89 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 |
---|---|---|
|
@@ -7,17 +7,25 @@ | |
"main": "src/index.ts", | ||
"author": "Márcio Barbosa <[email protected]>", | ||
"license": "UNLICENSED", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.js" | ||
} | ||
}, | ||
"files": ["dist/**/*.js", "dist/**/*.d.ts", "package.json", "README.md"], | ||
"scripts": { | ||
"build": "bun build", | ||
"build": "bun build src/index.ts --outdir=dist", | ||
"test": "bun test", | ||
"doctest": "bun run src/lib/doctest.test.ts", | ||
"format": "biome check", | ||
"format:fix": "biome check --write" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "1.8.3", | ||
"@supabase/doctest-js": "^0.1.0", | ||
"@types/bun": "^1.1.6", | ||
"husky": "^9.0.11", | ||
"msw": "^2.3.1" | ||
}, | ||
"peerDependencies": { | ||
|
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,2 +1,3 @@ | ||
export * from "./functions/report-event"; | ||
export * from "./functions/create-auction"; | ||
export * from "./interfaces/events.interface"; |
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,99 +1,78 @@ | ||
import { afterAll, afterEach, beforeAll, describe, expect, it } from "bun:test"; | ||
import * as path from "node:path"; | ||
import { setupServer } from "msw/node"; | ||
import { apis, baseURL } from "../constants/apis.constant"; | ||
import { handlers } from "../constants/handlers.constant"; | ||
import { reportEvent } from "../functions/report-event"; | ||
import APIClient from "../lib/api-client"; | ||
import { generateTestCases } from "../lib/generate-test-cases"; | ||
// import * as path from "node:path"; | ||
// import { describe, it, expect, beforeAll, afterAll, afterEach } from "bun:test"; | ||
// import { generateTestCases } from "../lib/generate-test-cases"; | ||
// import { reportEvent } from "../functions/report-event"; | ||
// import { apis, baseURL } from "../constants/apis.constant"; | ||
// import APIClient from "../lib/api-client"; | ||
// import { setupServer } from "msw/node"; | ||
// import { handlers } from "../constants/handlers.constant"; | ||
|
||
const server = setupServer(handlers.test); | ||
const filePath = path.resolve(__dirname, "../functions/report-event.ts"); | ||
// const server = setupServer(handlers.test); | ||
// const filePath = path.resolve(__dirname, "../functions/report-event.ts"); | ||
|
||
interface TestCaseInterface { | ||
code: string; | ||
expected: unknown; | ||
} | ||
// interface TestCaseInterface { | ||
// code: string; | ||
// expected: unknown; | ||
// } | ||
|
||
let testCases: TestCaseInterface[] = []; | ||
// let testCases: TestCaseInterface[] = []; | ||
|
||
beforeAll(async () => { | ||
server.listen(); | ||
testCases = await generateTestCases(filePath); | ||
console.log("Test cases:", testCases); | ||
}); | ||
// beforeAll(async () => { | ||
// server.listen(); | ||
// testCases = await generateTestCases(filePath); | ||
// console.log("Test cases:", testCases); | ||
// }); | ||
|
||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
// afterEach(() => server.resetHandlers()); | ||
// afterAll(() => server.close()); | ||
|
||
describe("doctest", () => { | ||
console.log("Test cases:", testCases); | ||
testCases = [ | ||
{ | ||
code: 'const event = { eventType: "test", eventData: {} };\nconst config = { token: "my-token" };\nconst result = await reportEvent(event, config);\n // { "ok": true, "retry": false }', | ||
expected: { | ||
ok: true, | ||
retry: false, | ||
}, | ||
}, | ||
]; | ||
// describe("doctest", () => { | ||
// console.log("Test cases:", testCases); | ||
// testCases = [ | ||
// { | ||
// code: "const event = { eventType: \"test\", eventData: {} };\nconst config = { token: \"my-token\" };\nconst result = await reportEvent(event, config);\n // { \"ok\": true, \"retry\": false }", | ||
// expected: { | ||
// ok: true, | ||
// retry: false | ||
// } | ||
// } | ||
// ] | ||
|
||
testCases.forEach((testCase, index) => { | ||
it(`example ${index + 1}`, async () => { | ||
const code = ` | ||
(async () => { | ||
const event = { eventType: "test", eventData: {} }; | ||
const config = { token: "my-token", apiKey: "test-api-key" }; | ||
const result = await reportEvent(event, config); | ||
return result; | ||
})(); | ||
`; | ||
// testCases.forEach((testCase, index) => { | ||
// it(`example ${index + 1}`, async () => { | ||
// const code = ` | ||
// (async () => { | ||
// const event = { eventType: "test", eventData: {} }; | ||
// const config = { token: "my-token", apiKey: "test-api-key" }; | ||
// const result = await reportEvent(event, config); | ||
// return result; | ||
// })(); | ||
// `; | ||
|
||
const func = new Function( | ||
"require", | ||
"exports", | ||
"module", | ||
"__filename", | ||
"__dirname", | ||
"reportEvent", | ||
"apis", | ||
"baseURL", | ||
"APIClient", | ||
code, | ||
); | ||
const exports: unknown = {}; | ||
const module = { exports }; | ||
// const func = new Function("require", "exports", "module", "__filename", "__dirname", "reportEvent", "apis", "baseURL", "APIClient", code); | ||
// const exports: unknown = {}; | ||
// const module = { exports }; | ||
|
||
// Mock require function | ||
const customRequire = (moduleName: string): unknown => { | ||
if (moduleName === "../functions/report-event") { | ||
return { reportEvent }; | ||
} | ||
if (moduleName === "../constants/apis.constant") { | ||
return { apis, baseURL }; | ||
} | ||
if (moduleName === "../lib/api-client") { | ||
return APIClient; | ||
} | ||
throw new Error(`Module not found: ${moduleName}`); | ||
}; | ||
// // Mock require function | ||
// const customRequire = (moduleName: string): unknown => { | ||
// if (moduleName === "../functions/report-event") { | ||
// return { reportEvent }; | ||
// } | ||
// if (moduleName === "../constants/apis.constant") { | ||
// return { apis, baseURL }; | ||
// } | ||
// if (moduleName === "../lib/api-client") { | ||
// return APIClient; | ||
// } | ||
// throw new Error(`Module not found: ${moduleName}`); | ||
// }; | ||
|
||
const result = await func( | ||
customRequire, | ||
exports, | ||
module, | ||
__filename, | ||
__dirname, | ||
reportEvent, | ||
apis, | ||
baseURL, | ||
APIClient, | ||
); | ||
// const result = await func(customRequire, exports, module, __filename, __dirname, reportEvent, apis, baseURL, APIClient); | ||
|
||
console.log("Result:", result); // Debugging line | ||
// console.log("Result:", result); // Debugging line | ||
|
||
expect(result).toBeDefined(); | ||
expect(result).toEqual(testCase.expected); | ||
}); | ||
}); | ||
}); | ||
// expect(result).toBeDefined(); | ||
// expect(result).toEqual(testCase.expected); | ||
// }); | ||
// }); | ||
// }); |