diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 4cde94dbe..efeeaa928 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -84,3 +84,27 @@ jobs: target/capi/**/_chainName key: ${{ runner.os }}-capi-metadata-${{ hashFiles('import_map.json') }} - run: deno task test + examples-deno: + name: Examples (Deno) + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v3 + - uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.0 + with: + deno-version: v1.x + - name: Cache Deno dependencies + uses: actions/cache@v3 + with: + path: | + ~/.deno + ~/.cache/deno + key: ${{ runner.os }}-deno-${{ hashFiles('deps/**/*.ts') }} + - name: Cache metadata + uses: actions/cache@v3 + with: + path: | + target/capi/**/_metadata + target/capi/**/_chainName + key: ${{ runner.os }}-capi-metadata-${{ hashFiles('import_map.json') }} + - run: deno task test:examples:deno diff --git a/.trunignore b/.trunignore new file mode 100644 index 000000000..1123780eb --- /dev/null +++ b/.trunignore @@ -0,0 +1,3 @@ +examples/xcm/asset_teleportation.eg.ts +examples/smoldot.eg.ts +examples/ink/*.eg.ts diff --git a/_tasks/test_examples.ts b/_tasks/test_examples.ts deleted file mode 100644 index 43d8acee0..000000000 --- a/_tasks/test_examples.ts +++ /dev/null @@ -1,59 +0,0 @@ -// TODO: rename this task - -import { parse } from "../deps/std/flags.ts" -import { Buffer, readLines } from "../deps/std/io.ts" -import * as path from "../deps/std/path.ts" -import { readerFromStreamReader, writeAll } from "../deps/std/streams.ts" -import { assert } from "../deps/std/testing/asserts.ts" - -const { dir } = parse(Deno.args, { - string: ["dir"], - default: { - dir: "examples", - }, -}) - -const ignoreFile = await Deno.readTextFile(path.join(dir, ".ignore")) -const ignoredFiles = new Set(ignoreFile.split("\n")) - -const exampleFileNames = Array.from(Deno.readDirSync(dir)) - .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((name) => { - return t.step({ - name: name, - async fn() { - const command = new Deno.Command(Deno.execPath(), { - args: ["run", "-A", "-r=http://localhost:4646/", `${dir}/${name}`], - stdout: "piped", - stderr: "piped", - }) - const task = command.spawn() - const out = new Buffer() - await Promise.all([ - pipeThrough(readerFromStreamReader(task.stdout.getReader()), out), - pipeThrough(readerFromStreamReader(task.stderr.getReader()), 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}`) - }, - 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`)) - } -} diff --git a/deno.jsonc b/deno.jsonc index eb2fd97df..e87ed75e4 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -33,7 +33,7 @@ "udd": "deno run -A _tasks/udd.ts", "dnt": "deno task run _tasks/dnt.ts", "test": "deno task capi -- deno test -A -L=info --ignore=target --parallel -r=http://localhost:4646/", - "test:examples": "deno task test _tasks/test_examples.ts", + "test:examples:deno": "deno task capi -- deno run -A -r=http://localhost:4646/ https://deno.land/x/trun@v0.1.0-beta.2/main.ts --include \"**/*.eg.ts\" --import-map import_map.json --concurrency 4 --reload http://localhost:4646/", "test:update": "deno task test -- --update", "moderate": "deno run -A https://deno.land/x/moderate@0.0.5/mod.ts --exclude '*.test.ts' && dprint fmt", "capi": "deno run -A main.ts", diff --git a/deps/capi_binary_builds.ts b/deps/capi_binary_builds.ts index 3ae235f84..76308a46f 100644 --- a/deps/capi_binary_builds.ts +++ b/deps/capi_binary_builds.ts @@ -1 +1 @@ -export * from "https://raw.githubusercontent.com/paritytech/capi-binary-builds/ee456af/download.ts" +export * from "https://raw.githubusercontent.com/paritytech/capi-binary-builds/28444f4/download.ts" diff --git a/deps/shiki.ts b/deps/shiki.ts index 9ad2f37c3..ace333d60 100644 --- a/deps/shiki.ts +++ b/deps/shiki.ts @@ -1,4 +1,4 @@ -import * as shiki from "https://esm.sh/shiki@0.14.1?bundle" +import * as shiki from "https://esm.sh/v113/shiki@0.14.1?bundle" import typescriptLang from "https://unpkg.com/shiki@0.14.1/languages/typescript.tmLanguage.json" assert { type: "json", } diff --git a/examples/.ignore b/examples/.ignore deleted file mode 100644 index 70c4db99f..000000000 --- a/examples/.ignore +++ /dev/null @@ -1,3 +0,0 @@ -ink/deploy.eg.ts -smoldot.eg.ts -xcm/asset_teleportation.ts diff --git a/examples/raw_rpc/subscription.eg.ts b/examples/raw_rpc/subscription.eg.ts index a2603a600..18cb83c0f 100644 --- a/examples/raw_rpc/subscription.eg.ts +++ b/examples/raw_rpc/subscription.eg.ts @@ -12,8 +12,11 @@ const headerIter = chain.connection .subscribe("chain_subscribeFinalizedHeads", "chain_unsubscribeAllHeads") .iter() +let count = 0 // Iterate over its items and ensure they conform to the expected shape. for await (const header of headerIter) { $.assert(known.$header, header) console.log(header) + count += 1 + if (count === 3) break } diff --git a/examples/rune/u_track.eg.ts b/examples/rune/u_track.eg.ts index a7ea355a2..995b02438 100644 --- a/examples/rune/u_track.eg.ts +++ b/examples/rune/u_track.eg.ts @@ -50,7 +50,7 @@ const unReHandled = await start .map((msg) => `**${msg}**`) .rehandle(MyError) .run() -console.log("(Un|Re)handled", unReHandled) +console.log("(Un|Re)handled:", unReHandled) assert(unReHandled === `**${INITIAL_MSG}**` || unReHandled instanceof MyError) // When rehandling, we can optionally specify the alternative execution, as we do with `handle`. @@ -59,4 +59,4 @@ const unReHandledWithFallback = await start .rehandle(MyError, () => Rune.constant(RECOVERY_MSG)) .run() console.log("(Un|Re)handled with fallback:", unReHandledWithFallback) -assert(unReHandledWithFallback === `**${INITIAL_MSG}**` || unReHandledWithFallback === RECOVERY_MSG) +assert(unReHandledWithFallback === INITIAL_MSG || unReHandledWithFallback === RECOVERY_MSG) diff --git a/words.txt b/words.txt index bb0f3616e..6028c1ed8 100644 --- a/words.txt +++ b/words.txt @@ -212,6 +212,7 @@ tpeyg transcoders trufflehog trufflesecurity +trun twind twox typebox