-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Solve [MET 710](https://linear.app/metatypedev/issue/MET-710/watch-artifacts). <!-- 2. Explain WHY the change cannot be made simpler --> - ... <!-- 3. Explain HOW users should update their code --> #### Migration notes --- - [x] The change comes with new or modified tests - [ ] Hard-to-understand functions have explanatory comments - [ ] End-user documentation is updated to reflect the change
- Loading branch information
1 parent
1cbbe57
commit 3c27fca
Showing
9 changed files
with
171 additions
and
23 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
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
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,3 @@ | ||
export function add({ lhs, rhs }: { lhs: number; rhs: number }) { | ||
return lhs + rhs; | ||
} |
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,16 @@ | ||
import { Policy, t, typegraph } from "@typegraph/sdk/index.ts"; | ||
import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.ts"; | ||
|
||
await typegraph("deps", (g) => { | ||
const pub = Policy.public(); | ||
const deno = new DenoRuntime(); | ||
|
||
g.expose({ | ||
add: deno | ||
.import(t.struct({ lhs: t.integer(), rhs: t.integer() }), t.integer(), { | ||
name: "add", | ||
module: "../deps/ops.ts", | ||
}) | ||
.withPolicy(pub), | ||
}); | ||
}); |
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,76 @@ | ||
// Copyright Metatype OÜ, licensed under the Elastic License 2.0. | ||
// SPDX-License-Identifier: Elastic-2.0 | ||
|
||
import * as path from "@std/path"; | ||
import { Meta } from "test-utils/mod.ts"; | ||
import { MetaTest } from "test-utils/test.ts"; | ||
import { killProcess, Lines } from "test-utils/process.ts"; | ||
|
||
const typegraphConfig = ` | ||
typegraphs: | ||
typescript: | ||
include: "api/example.ts"`; | ||
|
||
async function setupDirectory(t: MetaTest, dir: string) { | ||
await t.shell([ | ||
"bash", | ||
"-c", | ||
` | ||
rm -rf ./tmp && mkdir -p tmp/deps | ||
meta new --template deno ${dir} | ||
cp ./e2e/cli/typegraphs/deps.ts ${path.join(dir, "api", "example.ts")} | ||
cp ./e2e/cli/artifacts/ops.ts ${path.join(dir, "deps", "ops.ts")} | ||
echo "${typegraphConfig}" >> ${path.join(dir, "metatype.yaml")} | ||
`, | ||
]); | ||
} | ||
|
||
Meta.test({ name: "meta dev: watch artifacts" }, async (t) => { | ||
const targetDir = path.join(t.workingDir, "tmp"); | ||
|
||
console.log("Preparing test directory..."); | ||
|
||
await setupDirectory(t, targetDir); | ||
|
||
const metadev = new Deno.Command("meta", { | ||
cwd: targetDir, | ||
args: ["dev", `--gate=http://localhost:${t.port}`], | ||
stderr: "piped", | ||
}).spawn(); | ||
|
||
const stderr = new Lines(metadev.stderr); | ||
|
||
await t.should("upload artifact", async () => { | ||
await stderr.readWhile((line) => !line.includes("artifact uploaded")); | ||
}); | ||
|
||
await t.should("deploy typegraph", async () => { | ||
await stderr.readWhile( | ||
(line) => !line.includes("successfully deployed typegraph"), | ||
); | ||
}); | ||
|
||
await t.shell(["bash", "-c", "echo '' >> deps/ops.ts"], { | ||
currentDir: targetDir, | ||
}); | ||
|
||
await t.should("watch modified file", async () => { | ||
await stderr.readWhile((line) => !line.includes("File modified")); | ||
}); | ||
|
||
await t.should("re-upload artifact", async () => { | ||
await stderr.readWhile((line) => !line.includes("artifact uploaded")); | ||
}); | ||
|
||
await t.should("re-deploy typegraph", async () => { | ||
await stderr.readWhile( | ||
(line) => !line.includes("successfully deployed typegraph"), | ||
); | ||
}); | ||
|
||
t.addCleanup(async () => { | ||
await stderr.close(); | ||
await killProcess(metadev); | ||
await t.shell(["rm", "-rf", targetDir]); | ||
}); | ||
}); |