This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
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.
feat: integrate examples as deno tests for ci
- Loading branch information
1 parent
cbc8b44
commit 76fb204
Showing
8 changed files
with
71 additions
and
29 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
"star": "deno task run _tasks/star.ts && deno cache --check target/star.ts", | ||
"codegen": "deno task run cache.ts examples/mod.ts", | ||
"test": "deno task run test_util/ctx.ts -- deno test -A -L=info --ignore=target --parallel", | ||
"test:ci": "ENV_TYPE_CI=1 deno task test", | ||
"test:update": "deno task test -- -- --update", | ||
"bench": "deno bench -A", | ||
"moderate": "deno task run https://deno.land/x/[email protected]/mod.ts && dprint fmt" | ||
|
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 @@ | ||
export * from "https://deno.land/x/[email protected]/mod.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 @@ | ||
export * from "https://deno.land/[email protected]/io/mod.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 @@ | ||
export * from "https://deno.land/[email protected]/streams/mod.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 |
---|---|---|
|
@@ -2,3 +2,4 @@ mod.ts | |
multisig_transfer.ts | ||
smart_contract.ts | ||
xcm_teleport_assets.ts | ||
examples.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,65 @@ | ||
import * as path from "http://localhost:5646/@local/deps/std/path.ts" | ||
import { makeRunWithLimit } from "../deps/run_with_limit.ts" | ||
import { Buffer, readLines } from "../deps/std/io.ts" | ||
import { writeAll } from "../deps/std/streams.ts" | ||
import { assert } from "../deps/std/testing/asserts.ts" | ||
|
||
type Output = readonly [name: string, status: Deno.ProcessStatus, out: Buffer] | ||
|
||
const { runWithLimit } = makeRunWithLimit<Output>(navigator.hardwareConcurrency) | ||
|
||
function getModuleDir(importMeta: ImportMeta): string { | ||
return path.resolve(path.dirname(path.fromFileUrl(importMeta.url))) | ||
} | ||
|
||
async function pipeThrough( | ||
reader: Deno.Reader, | ||
writer: Deno.Writer, | ||
) { | ||
const encoder = new TextEncoder() | ||
for await (const line of readLines(reader)) { | ||
await writeAll(writer, encoder.encode(`${line}\n`)) | ||
} | ||
} | ||
|
||
const ignoreFile = await Deno.readTextFile(path.join(getModuleDir(import.meta), ".ignore")) | ||
const ignoredFiles = new Set(ignoreFile.split("\n")) | ||
|
||
const exampleFileNames = Array.from(Deno.readDirSync(getModuleDir(import.meta))) | ||
.filter((e) => e.name.match(/^.*\.ts$/g) && e.isFile && !ignoredFiles.has(e.name)) | ||
.map((f) => f.name) | ||
|
||
const exampleTasks = exampleFileNames.map((fileName) => | ||
runWithLimit(async () => { | ||
const t = Deno.run({ | ||
cmd: ["deno", "task", "run", `${getModuleDir(import.meta)}/${fileName}`], | ||
stdout: "piped", | ||
stderr: "piped", | ||
}) | ||
|
||
const out = new Buffer() | ||
pipeThrough(t.stdout, out) | ||
pipeThrough(t.stderr, out) | ||
|
||
const status = await t.status() | ||
|
||
t.close() | ||
|
||
return [fileName, status, out] as const | ||
}) | ||
) | ||
|
||
const completedExamples = await Promise.all(exampleTasks) | ||
|
||
completedExamples.map((o) => { | ||
const [name, status, out] = o | ||
Deno.test({ | ||
name, | ||
ignore: Deno.env.get("ENV_TYPE_CI") ? true : false, | ||
async fn() { | ||
await pipeThrough(out, Deno.stdout) | ||
assert(status.code === 0, `task failed with status code: ${status.code}`) | ||
assert(status.success, `unsuccessful`) | ||
}, | ||
}) | ||
}) |