Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
feat: integrate examples as deno tests for ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanleecode committed Jan 23, 2023
1 parent cbc8b44 commit d6f22e4
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 29 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/spawn_examples.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
- run: deno lint
- run: deno task codegen
- run: deno task star
- run: deno task test
- run: deno task test:ci
1 change: 1 addition & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions deps/run_with_limit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "https://deno.land/x/[email protected]/mod.ts"
1 change: 1 addition & 0 deletions deps/std/io.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "https://deno.land/[email protected]/io/mod.ts"
1 change: 1 addition & 0 deletions deps/std/streams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "https://deno.land/[email protected]/streams/mod.ts"
1 change: 1 addition & 0 deletions examples/.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ mod.ts
multisig_transfer.ts
smart_contract.ts
xcm_teleport_assets.ts
examples.test.ts
61 changes: 61 additions & 0 deletions examples/examples.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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"

const IS_CI = Deno.env.get("ENV_TYPE_CI") ? true : false

const { runWithLimit } = makeRunWithLimit<void>(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 = IS_CI
? 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 Deno.test({
name: fileName,
async fn() {
await pipeThrough(out, Deno.stdout)
assert(status.code === 0, `task failed with status code: ${status.code}`)
assert(status.success, `unsuccessful`)
},
})
})
)
: []

await Promise.all(exampleTasks)

0 comments on commit d6f22e4

Please sign in to comment.