generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 9
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 #15 from Keyrxng/refactor/polymorphic-tests
Refactor/polymorphic tests
- Loading branch information
Showing
28 changed files
with
2,248 additions
and
2,442 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
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
"**/*.d.ts", | ||
"**/*.test.ts", | ||
"**/*-test.ts", | ||
"tests/", | ||
"jest.config.ts", | ||
"knip.ts", | ||
"build", | ||
|
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
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,17 +1,17 @@ | ||
nodeLinker: node-modules | ||
supportedArchitectures: | ||
supportedArchitectures: | ||
os: | ||
- 'current' | ||
- 'darwin' | ||
- 'linux' | ||
- 'win32' | ||
- "current" | ||
- "darwin" | ||
- "linux" | ||
- "win32" | ||
cpu: | ||
- 'current' | ||
- 'x64' | ||
- 'x86' | ||
- 'arm' | ||
- 'ia32' | ||
- "current" | ||
- "x64" | ||
- "x86" | ||
- "arm" | ||
- "ia32" | ||
libc: | ||
- 'current' | ||
- 'glibc' | ||
- 'musl' | ||
- "current" | ||
- "glibc" | ||
- "musl" |
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
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,86 @@ | ||
import esbuild from "esbuild"; | ||
import chainlist from "../lib/chainlist/constants/extraRpcs"; | ||
import chainIDList from "../lib/chainlist/constants/chainIds.json"; | ||
import path from "path"; | ||
import * as fs from "fs"; | ||
|
||
const typescriptEntries = ["tests/mocks/rpc-service.ts", "tests/mocks/rpc-handler.ts", "tests/mocks/handler.ts"]; | ||
export const entries = [...typescriptEntries]; | ||
const extraRpcs: Record<string, string[]> = {}; | ||
// this flattens all the rpcs into a single object, with key names that match the networkIds. The arrays are just of URLs per network ID. | ||
|
||
Object.keys(chainlist).forEach((networkId) => { | ||
const officialUrls = chainlist[networkId].rpcs.filter((rpc) => typeof rpc === "string"); | ||
const extraUrls: string[] = chainlist[networkId].rpcs.filter((rpc) => rpc.url !== undefined && rpc.tracking === "none").map((rpc) => rpc.url); | ||
|
||
extraRpcs[networkId] = [...officialUrls, ...extraUrls].filter((rpc) => rpc.startsWith("https://")); | ||
}); | ||
|
||
export const esBuildContext: esbuild.BuildOptions = { | ||
entryPoints: entries, | ||
bundle: true, | ||
|
||
outdir: "dist", | ||
define: createEnvDefines({ extraRpcs, chainIDList }), | ||
}; | ||
|
||
async function main() { | ||
try { | ||
await buildForEnvironments(); | ||
await buildIndex(); | ||
} catch (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main(); | ||
|
||
async function buildForEnvironments() { | ||
ensureDistDir(); | ||
|
||
await esbuild | ||
.build({ | ||
...esBuildContext, | ||
tsconfig: "tsconfig.tests.json", | ||
platform: "node", | ||
outdir: "dist/tests/mocks", | ||
format: "cjs", | ||
}) | ||
.then(() => { | ||
console.log("Node.js esbuild complete"); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
} | ||
|
||
async function buildIndex() { | ||
await esbuild.build({ | ||
entryPoints: ["index.ts"], | ||
bundle: true, | ||
format: "cjs", | ||
outfile: "dist/index.js", | ||
define: createEnvDefines({ extraRpcs, chainIDList }), | ||
}); | ||
|
||
console.log("Index build complete."); | ||
} | ||
|
||
function createEnvDefines(generatedAtBuild: Record<string, unknown>): Record<string, string> { | ||
const defines: Record<string, string> = {}; | ||
|
||
Object.keys(generatedAtBuild).forEach((key) => { | ||
defines[key] = JSON.stringify(generatedAtBuild[key]); | ||
}); | ||
|
||
return defines; | ||
} | ||
|
||
function ensureDistDir() { | ||
const distPath = path.resolve(__dirname, "dist"); | ||
if (!fs.existsSync(distPath)) { | ||
fs.mkdirSync(distPath, { recursive: true }); | ||
} | ||
} |
Oops, something went wrong.