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 (#510)
- Loading branch information
1 parent
cbc8b44
commit 74a9eb2
Showing
9 changed files
with
120 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ jobs: | |
- run: deno task codegen | ||
- run: deno task star | ||
- run: deno task test | ||
- run: deno task test:examples |
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,66 @@ | ||
import { Buffer, readLines } from "../deps/std/io.ts" | ||
import * as path from "../deps/std/path.ts" | ||
import { writeAll } from "../deps/std/streams.ts" | ||
import { assert } from "../deps/std/testing/asserts.ts" | ||
|
||
const examplesDir = Deno.args[0] | ||
if (!examplesDir) { | ||
throw new Error("specify examples directory as first CLI argument") | ||
} | ||
|
||
const ignoreFile = await Deno.readTextFile(path.join(examplesDir, ".ignore")) | ||
const ignoredFiles = new Set(ignoreFile.split("\n")) | ||
|
||
const exampleFileNames = Array.from(Deno.readDirSync(examplesDir)) | ||
.filter((e) => e.name.match(/^.*\.ts$/g) && e.isFile && !ignoredFiles.has(e.name)) | ||
.map((f) => f.name) | ||
|
||
Deno.test("examples", async (t) => { | ||
await Promise.all(exampleFileNames.map((fileName) => { | ||
return t.step({ | ||
name: fileName, | ||
async fn() { | ||
const task = Deno.run({ | ||
cmd: ["deno", "task", "run", `${examplesDir}/${fileName}`], | ||
stdout: "piped", | ||
stderr: "piped", | ||
}) | ||
|
||
try { | ||
const out = new Buffer() | ||
|
||
await Promise.all([ | ||
pipeThrough(task.stdout, out), | ||
pipeThrough(task.stderr, out), | ||
]) | ||
|
||
const status = await task.status() | ||
|
||
if (!status.success) { | ||
for await (const line of readLines(out)) { | ||
console.log(line) | ||
} | ||
} | ||
assert(status.success, `task failed with status code: ${status.code}`) | ||
} finally { | ||
task.stdout.close() | ||
task.stderr.close() | ||
task.close() | ||
} | ||
}, | ||
sanitizeExit: false, | ||
sanitizeOps: false, | ||
sanitizeResources: false, | ||
}) | ||
})) | ||
}) | ||
|
||
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`)) | ||
} | ||
} |
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:examples": "deno task test _tasks/test_examples.ts -- examples", | ||
"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/[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
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,38 +1,34 @@ | ||
import { createTestPairs } from "https://deno.land/x/[email protected]/keyring/mod.ts" | ||
import { TypeRegistry } from "https://deno.land/x/[email protected]/types/mod.ts" | ||
|
||
import * as C from "http://localhost:5646/@local/mod.ts" | ||
import { collectExtrinsicEvents } from "http://localhost:5646/@local/test_util/extrinsic.ts" | ||
|
||
import * as T from "http://localhost:5646/@local/test_util/mod.ts" | ||
import * as U from "http://localhost:5646/@local/util/mod.ts" | ||
import { createTestPairs } from "https://deno.land/x/[email protected]/keyring/mod.ts" | ||
import { TypeRegistry } from "https://deno.land/x/[email protected]/types/mod.ts" | ||
|
||
const root = C.extrinsic(T.westend)({ | ||
sender: T.alice.address, | ||
call: { | ||
type: "Balances", | ||
value: { | ||
type: "transfer", | ||
value: 12345n, | ||
dest: T.bob.address, | ||
const root = collectExtrinsicEvents( | ||
C.extrinsic(T.westend)({ | ||
sender: T.dave.address, | ||
call: { | ||
type: "Balances", | ||
value: { | ||
type: "transfer", | ||
value: 12345n, | ||
dest: T.bob.address, | ||
}, | ||
}, | ||
}, | ||
}) | ||
.signed({ | ||
signPayload(payload) { | ||
const tr = new TypeRegistry() | ||
tr.setSignedExtensions(payload.signedExtensions) | ||
return Promise.resolve( | ||
tr | ||
.createType("ExtrinsicPayload", payload, { version: payload.version }) | ||
.sign(createTestPairs().alice!), | ||
) | ||
}, | ||
}) | ||
.watch((ctx) => (status) => { | ||
console.log(status) | ||
if (C.rpc.known.TransactionStatus.isTerminal(status)) { | ||
return ctx.end() | ||
} | ||
return | ||
}) | ||
.signed({ | ||
signPayload(payload) { | ||
const tr = new TypeRegistry() | ||
tr.setSignedExtensions(payload.signedExtensions) | ||
return Promise.resolve( | ||
tr | ||
.createType("ExtrinsicPayload", payload, { version: payload.version }) | ||
.sign(createTestPairs().dave!), | ||
) | ||
}, | ||
}), | ||
).next(console.log) | ||
|
||
U.throwIfError(await root.run()) |