summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/specs/compile/patch/__test__.jsonc22
-rw-r--r--tests/specs/compile/patch/add/deno.json4
-rw-r--r--tests/specs/compile/patch/add/mod.ts3
-rw-r--r--tests/specs/compile/patch/main.out1
-rw-r--r--tests/specs/compile/patch/main/deno.json5
-rw-r--r--tests/specs/compile/patch/main/main.ts3
-rw-r--r--tests/specs/mod.rs11
-rw-r--r--tests/specs/run/patch/__test__.jsonc25
-rw-r--r--tests/specs/run/patch/add/deno.json5
-rw-r--r--tests/specs/run/patch/add/mod.test.ts9
-rw-r--r--tests/specs/run/patch/add/mod.ts4
-rw-r--r--tests/specs/run/patch/modify_version.ts3
-rw-r--r--tests/specs/run/patch/my-pkg/deno.json11
-rw-r--r--tests/specs/run/patch/my-pkg/mod.test.ts7
-rw-r--r--tests/specs/run/patch/my-pkg/mod.ts2
-rw-r--r--tests/specs/run/patch/not_matching_version.out11
-rw-r--r--tests/specs/run/patch/test.out10
-rw-r--r--tests/specs/run/workspaces/member_not_match_constraint/__test__.jsonc4
-rw-r--r--tests/specs/run/workspaces/member_not_match_constraint/add/deno.json5
-rw-r--r--tests/specs/run/workspaces/member_not_match_constraint/add/mod.ts4
-rw-r--r--tests/specs/run/workspaces/member_not_match_constraint/deno.json3
-rw-r--r--tests/specs/run/workspaces/member_not_match_constraint/deno.lock23
-rw-r--r--tests/specs/run/workspaces/member_not_match_constraint/subtract/deno.json8
-rw-r--r--tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.test.ts7
-rw-r--r--tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.ts5
-rw-r--r--tests/specs/run/workspaces/member_not_match_constraint/test.out11
-rw-r--r--tests/specs/workspaces/patch/__test__.jsonc13
-rw-r--r--tests/specs/workspaces/patch/add/deno.json5
-rw-r--r--tests/specs/workspaces/patch/add/mod.test.ts9
-rw-r--r--tests/specs/workspaces/patch/add/mod.ts4
-rw-r--r--tests/specs/workspaces/patch/test.out10
-rw-r--r--tests/specs/workspaces/patch/workspace/deno.json6
-rw-r--r--tests/specs/workspaces/patch/workspace/my-pkg/deno.json8
-rw-r--r--tests/specs/workspaces/patch/workspace/my-pkg/mod.test.ts7
-rw-r--r--tests/specs/workspaces/patch/workspace/my-pkg/mod.ts1
35 files changed, 268 insertions, 1 deletions
diff --git a/tests/specs/compile/patch/__test__.jsonc b/tests/specs/compile/patch/__test__.jsonc
new file mode 100644
index 000000000..87abf82a7
--- /dev/null
+++ b/tests/specs/compile/patch/__test__.jsonc
@@ -0,0 +1,22 @@
+{
+ "tempDir": true,
+ "steps": [{
+ "if": "unix",
+ "args": "compile --output my-app main/main.ts",
+ "output": "[WILDCARD]"
+ }, {
+ "if": "unix",
+ "commandName": "./my-app",
+ "args": [],
+ "output": "main.out"
+ }, {
+ "if": "windows",
+ "args": "compile --output my-app.exe main/main.ts",
+ "output": "[WILDCARD]"
+ }, {
+ "if": "windows",
+ "commandName": "./my-app.exe",
+ "args": [],
+ "output": "main.out"
+ }]
+}
diff --git a/tests/specs/compile/patch/add/deno.json b/tests/specs/compile/patch/add/deno.json
new file mode 100644
index 000000000..40e417993
--- /dev/null
+++ b/tests/specs/compile/patch/add/deno.json
@@ -0,0 +1,4 @@
+{
+ "name": "@denotest/add",
+ "exports": "./mod.ts"
+}
diff --git a/tests/specs/compile/patch/add/mod.ts b/tests/specs/compile/patch/add/mod.ts
new file mode 100644
index 000000000..7e841b3bf
--- /dev/null
+++ b/tests/specs/compile/patch/add/mod.ts
@@ -0,0 +1,3 @@
+export function add(a: number, b: number): number {
+ return (a + b) * 2; // it adds wrong
+}
diff --git a/tests/specs/compile/patch/main.out b/tests/specs/compile/patch/main.out
new file mode 100644
index 000000000..1e8b31496
--- /dev/null
+++ b/tests/specs/compile/patch/main.out
@@ -0,0 +1 @@
+6
diff --git a/tests/specs/compile/patch/main/deno.json b/tests/specs/compile/patch/main/deno.json
new file mode 100644
index 000000000..5d341f168
--- /dev/null
+++ b/tests/specs/compile/patch/main/deno.json
@@ -0,0 +1,5 @@
+{
+ "patch": [
+ "../add"
+ ]
+}
diff --git a/tests/specs/compile/patch/main/main.ts b/tests/specs/compile/patch/main/main.ts
new file mode 100644
index 000000000..8fb44d2ed
--- /dev/null
+++ b/tests/specs/compile/patch/main/main.ts
@@ -0,0 +1,3 @@
+import { add } from "jsr:@denotest/add";
+
+console.log(add(1, 2));
diff --git a/tests/specs/mod.rs b/tests/specs/mod.rs
index c46969f4e..7a3572a94 100644
--- a/tests/specs/mod.rs
+++ b/tests/specs/mod.rs
@@ -53,6 +53,8 @@ struct MultiTestMetaData {
#[serde(default)]
pub envs: HashMap<String, String>,
#[serde(default)]
+ pub cwd: Option<String>,
+ #[serde(default)]
pub tests: BTreeMap<String, JsonMap>,
}
@@ -73,6 +75,10 @@ impl MultiTestMetaData {
if multi_test_meta_data.temp_dir && !value.contains_key("tempDir") {
value.insert("tempDir".to_string(), true.into());
}
+ if multi_test_meta_data.cwd.is_some() && !value.contains_key("cwd") {
+ value
+ .insert("cwd".to_string(), multi_test_meta_data.cwd.clone().into());
+ }
if !multi_test_meta_data.envs.is_empty() {
if !value.contains_key("envs") {
value.insert("envs".to_string(), JsonMap::default().into());
@@ -112,6 +118,8 @@ struct MultiStepMetaData {
#[serde(default)]
pub base: Option<String>,
#[serde(default)]
+ pub cwd: Option<String>,
+ #[serde(default)]
pub envs: HashMap<String, String>,
#[serde(default)]
pub repeat: Option<usize>,
@@ -136,6 +144,7 @@ impl SingleTestMetaData {
pub fn into_multi(self) -> MultiStepMetaData {
MultiStepMetaData {
base: self.base,
+ cwd: None,
temp_dir: self.temp_dir,
repeat: self.repeat,
envs: Default::default(),
@@ -371,7 +380,7 @@ fn run_step(
VecOrString::Vec(args) => command.args_vec(args),
VecOrString::String(text) => command.args(text),
};
- let command = match &step.cwd {
+ let command = match step.cwd.as_ref().or(metadata.cwd.as_ref()) {
Some(cwd) => command.current_dir(cwd),
None => command,
};
diff --git a/tests/specs/run/patch/__test__.jsonc b/tests/specs/run/patch/__test__.jsonc
new file mode 100644
index 000000000..00ae3baac
--- /dev/null
+++ b/tests/specs/run/patch/__test__.jsonc
@@ -0,0 +1,25 @@
+{
+ "tempDir": true,
+ "tests": {
+ "matching_version": {
+ "cwd": "./my-pkg",
+ "steps": [{
+ "args": "test",
+ "output": "test.out"
+ }, {
+ "args": "lint",
+ "output": "Checked 2 files\n"
+ }]
+ },
+ "not_matching_version": {
+ "steps": [{
+ "args": "run --allow-read=. --allow-write=. modify_version.ts",
+ "output": "[WILDCARD]"
+ }, {
+ "cwd": "./my-pkg",
+ "args": "test",
+ "output": "not_matching_version.out"
+ }]
+ }
+ }
+}
diff --git a/tests/specs/run/patch/add/deno.json b/tests/specs/run/patch/add/deno.json
new file mode 100644
index 000000000..05d24d7b5
--- /dev/null
+++ b/tests/specs/run/patch/add/deno.json
@@ -0,0 +1,5 @@
+{
+ "name": "@denotest/add",
+ "version": "1.0.0",
+ "exports": "./mod.ts"
+}
diff --git a/tests/specs/run/patch/add/mod.test.ts b/tests/specs/run/patch/add/mod.test.ts
new file mode 100644
index 000000000..3d3804e07
--- /dev/null
+++ b/tests/specs/run/patch/add/mod.test.ts
@@ -0,0 +1,9 @@
+import { add } from "./mod.ts";
+
+// this test should not be run or linted
+Deno.test("add", () => {
+ let unusedVar = 5; // purposefully causing a lint error to ensure it's not linted
+ if (add(1, 2) !== 3) {
+ throw new Error("fail");
+ }
+});
diff --git a/tests/specs/run/patch/add/mod.ts b/tests/specs/run/patch/add/mod.ts
new file mode 100644
index 000000000..97a779a44
--- /dev/null
+++ b/tests/specs/run/patch/add/mod.ts
@@ -0,0 +1,4 @@
+export function add(a: number, b: number): number {
+ console.log("adding", a, "and", b);
+ return a + b;
+}
diff --git a/tests/specs/run/patch/modify_version.ts b/tests/specs/run/patch/modify_version.ts
new file mode 100644
index 000000000..3d59aa1b9
--- /dev/null
+++ b/tests/specs/run/patch/modify_version.ts
@@ -0,0 +1,3 @@
+const data = JSON.parse(Deno.readTextFileSync("./add/deno.json"));
+data.version = "2.0.0";
+Deno.writeTextFileSync("./add/deno.json", JSON.stringify(data, null, 2));
diff --git a/tests/specs/run/patch/my-pkg/deno.json b/tests/specs/run/patch/my-pkg/deno.json
new file mode 100644
index 000000000..0303c9974
--- /dev/null
+++ b/tests/specs/run/patch/my-pkg/deno.json
@@ -0,0 +1,11 @@
+{
+ "name": "@scope/my-pkg",
+ "version": "1.0.0",
+ "exports": "./mod.ts",
+ "imports": {
+ "@denotest/add": "jsr:@denotest/add@1"
+ },
+ "patch": [
+ "../add"
+ ]
+}
diff --git a/tests/specs/run/patch/my-pkg/mod.test.ts b/tests/specs/run/patch/my-pkg/mod.test.ts
new file mode 100644
index 000000000..1c694298c
--- /dev/null
+++ b/tests/specs/run/patch/my-pkg/mod.test.ts
@@ -0,0 +1,7 @@
+import { add } from "./mod.ts";
+
+Deno.test("add", () => {
+ if (add(1, 2) !== 3) {
+ throw new Error("fail");
+ }
+});
diff --git a/tests/specs/run/patch/my-pkg/mod.ts b/tests/specs/run/patch/my-pkg/mod.ts
new file mode 100644
index 000000000..41389ed65
--- /dev/null
+++ b/tests/specs/run/patch/my-pkg/mod.ts
@@ -0,0 +1,2 @@
+export { add } from "@denotest/add";
+import "@denotest/add"; // ensure it only warns once
diff --git a/tests/specs/run/patch/not_matching_version.out b/tests/specs/run/patch/not_matching_version.out
new file mode 100644
index 000000000..7a9ee6f39
--- /dev/null
+++ b/tests/specs/run/patch/not_matching_version.out
@@ -0,0 +1,11 @@
+Warning Patch '@denotest/add@2.0.0' was not used because it did not match '@denotest/add@1'
+ at file:///[WILDLINE]/my-pkg/mod.ts:1:21
+Download http://127.0.0.1:4250/@denotest/add/meta.json
+Download http://127.0.0.1:4250/@denotest/add/1.0.0_meta.json
+Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts
+Check file:///[WILDLINE]/mod.test.ts
+running 1 test from ./mod.test.ts
+add ... ok ([WILDLINE])
+
+ok | 1 passed | 0 failed ([WILDLINE])
+
diff --git a/tests/specs/run/patch/test.out b/tests/specs/run/patch/test.out
new file mode 100644
index 000000000..4eb9f3383
--- /dev/null
+++ b/tests/specs/run/patch/test.out
@@ -0,0 +1,10 @@
+Check file:///[WILDLINE]/mod.test.ts
+running 1 test from ./mod.test.ts
+add ...
+------- output -------
+adding 1 and 2
+----- output end -----
+add ... ok ([WILDLINE])
+
+ok | 1 passed | 0 failed ([WILDLINE])
+
diff --git a/tests/specs/run/workspaces/member_not_match_constraint/__test__.jsonc b/tests/specs/run/workspaces/member_not_match_constraint/__test__.jsonc
new file mode 100644
index 000000000..532705939
--- /dev/null
+++ b/tests/specs/run/workspaces/member_not_match_constraint/__test__.jsonc
@@ -0,0 +1,4 @@
+{
+ "args": "test",
+ "output": "test.out"
+}
diff --git a/tests/specs/run/workspaces/member_not_match_constraint/add/deno.json b/tests/specs/run/workspaces/member_not_match_constraint/add/deno.json
new file mode 100644
index 000000000..ff1abb9fe
--- /dev/null
+++ b/tests/specs/run/workspaces/member_not_match_constraint/add/deno.json
@@ -0,0 +1,5 @@
+{
+ "name": "@denotest/add",
+ "version": "2.0.0",
+ "exports": "./mod.ts"
+}
diff --git a/tests/specs/run/workspaces/member_not_match_constraint/add/mod.ts b/tests/specs/run/workspaces/member_not_match_constraint/add/mod.ts
new file mode 100644
index 000000000..2c8d7ef7a
--- /dev/null
+++ b/tests/specs/run/workspaces/member_not_match_constraint/add/mod.ts
@@ -0,0 +1,4 @@
+export function add(a: number, b: number): number {
+ console.log("local");
+ return a + b;
+}
diff --git a/tests/specs/run/workspaces/member_not_match_constraint/deno.json b/tests/specs/run/workspaces/member_not_match_constraint/deno.json
new file mode 100644
index 000000000..ec5dc2bdf
--- /dev/null
+++ b/tests/specs/run/workspaces/member_not_match_constraint/deno.json
@@ -0,0 +1,3 @@
+{
+ "workspace": ["./add", "./subtract"]
+}
diff --git a/tests/specs/run/workspaces/member_not_match_constraint/deno.lock b/tests/specs/run/workspaces/member_not_match_constraint/deno.lock
new file mode 100644
index 000000000..373359d72
--- /dev/null
+++ b/tests/specs/run/workspaces/member_not_match_constraint/deno.lock
@@ -0,0 +1,23 @@
+{
+ "version": "3",
+ "packages": {
+ "specifiers": {
+ "jsr:@denotest/add@1": "jsr:@denotest/add@1.0.0"
+ },
+ "jsr": {
+ "@denotest/add@1.0.0": {
+ "integrity": "3b2e675c1ad7fba2a45bc251992e01aff08a3c974ac09079b11e6a5b95d4bfcb"
+ }
+ }
+ },
+ "remote": {},
+ "workspace": {
+ "members": {
+ "subtract": {
+ "dependencies": [
+ "jsr:@denotest/add@1"
+ ]
+ }
+ }
+ }
+}
diff --git a/tests/specs/run/workspaces/member_not_match_constraint/subtract/deno.json b/tests/specs/run/workspaces/member_not_match_constraint/subtract/deno.json
new file mode 100644
index 000000000..e585197c0
--- /dev/null
+++ b/tests/specs/run/workspaces/member_not_match_constraint/subtract/deno.json
@@ -0,0 +1,8 @@
+{
+ "name": "@denotest/subtract",
+ "version": "1.0.0",
+ "exports": "./mod.ts",
+ "imports": {
+ "@denotest/add": "jsr:@denotest/add@1"
+ }
+}
diff --git a/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.test.ts b/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.test.ts
new file mode 100644
index 000000000..7d699d4d7
--- /dev/null
+++ b/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.test.ts
@@ -0,0 +1,7 @@
+import { subtract } from "./mod.ts";
+
+Deno.test("subtract", () => {
+ if (subtract(3, 2) !== 1) {
+ throw new Error("fail");
+ }
+});
diff --git a/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.ts b/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.ts
new file mode 100644
index 000000000..6e301511b
--- /dev/null
+++ b/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.ts
@@ -0,0 +1,5 @@
+import { add } from "@denotest/add";
+
+export function subtract(a: number, b: number): number {
+ return add(a, -b);
+}
diff --git a/tests/specs/run/workspaces/member_not_match_constraint/test.out b/tests/specs/run/workspaces/member_not_match_constraint/test.out
new file mode 100644
index 000000000..0e16426c6
--- /dev/null
+++ b/tests/specs/run/workspaces/member_not_match_constraint/test.out
@@ -0,0 +1,11 @@
+Warning Workspace member '@denotest/add@2.0.0' was not used because it did not match '@denotest/add@1'
+ at file:///[WILDLINE]/mod.ts:1:21
+Download http://127.0.0.1:4250/@denotest/add/meta.json
+Download http://127.0.0.1:4250/@denotest/add/1.0.0_meta.json
+Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts
+Check file:///[WILDLINE]/mod.test.ts
+running 1 test from ./subtract/mod.test.ts
+subtract ... ok ([WILDLINE])
+
+ok | 1 passed | 0 failed ([WILDLINE])
+
diff --git a/tests/specs/workspaces/patch/__test__.jsonc b/tests/specs/workspaces/patch/__test__.jsonc
new file mode 100644
index 000000000..90a54086e
--- /dev/null
+++ b/tests/specs/workspaces/patch/__test__.jsonc
@@ -0,0 +1,13 @@
+{
+ "cwd": "./workspace",
+ "tests": {
+ "lint": {
+ "args": "lint",
+ "output": "Checked 2 files\n"
+ },
+ "test": {
+ "args": "test",
+ "output": "test.out"
+ }
+ }
+}
diff --git a/tests/specs/workspaces/patch/add/deno.json b/tests/specs/workspaces/patch/add/deno.json
new file mode 100644
index 000000000..05d24d7b5
--- /dev/null
+++ b/tests/specs/workspaces/patch/add/deno.json
@@ -0,0 +1,5 @@
+{
+ "name": "@denotest/add",
+ "version": "1.0.0",
+ "exports": "./mod.ts"
+}
diff --git a/tests/specs/workspaces/patch/add/mod.test.ts b/tests/specs/workspaces/patch/add/mod.test.ts
new file mode 100644
index 000000000..3d3804e07
--- /dev/null
+++ b/tests/specs/workspaces/patch/add/mod.test.ts
@@ -0,0 +1,9 @@
+import { add } from "./mod.ts";
+
+// this test should not be run or linted
+Deno.test("add", () => {
+ let unusedVar = 5; // purposefully causing a lint error to ensure it's not linted
+ if (add(1, 2) !== 3) {
+ throw new Error("fail");
+ }
+});
diff --git a/tests/specs/workspaces/patch/add/mod.ts b/tests/specs/workspaces/patch/add/mod.ts
new file mode 100644
index 000000000..97a779a44
--- /dev/null
+++ b/tests/specs/workspaces/patch/add/mod.ts
@@ -0,0 +1,4 @@
+export function add(a: number, b: number): number {
+ console.log("adding", a, "and", b);
+ return a + b;
+}
diff --git a/tests/specs/workspaces/patch/test.out b/tests/specs/workspaces/patch/test.out
new file mode 100644
index 000000000..c35ac0e45
--- /dev/null
+++ b/tests/specs/workspaces/patch/test.out
@@ -0,0 +1,10 @@
+Check file:///[WILDLINE]/my-pkg/mod.test.ts
+running 1 test from ./my-pkg/mod.test.ts
+add ...
+------- output -------
+adding 1 and 2
+----- output end -----
+add ... ok ([WILDLINE])
+
+ok | 1 passed | 0 failed ([WILDLINE])
+
diff --git a/tests/specs/workspaces/patch/workspace/deno.json b/tests/specs/workspaces/patch/workspace/deno.json
new file mode 100644
index 000000000..510351c44
--- /dev/null
+++ b/tests/specs/workspaces/patch/workspace/deno.json
@@ -0,0 +1,6 @@
+{
+ "workspace": ["./my-pkg"],
+ "patch": [
+ "../add"
+ ]
+}
diff --git a/tests/specs/workspaces/patch/workspace/my-pkg/deno.json b/tests/specs/workspaces/patch/workspace/my-pkg/deno.json
new file mode 100644
index 000000000..8b2e887e7
--- /dev/null
+++ b/tests/specs/workspaces/patch/workspace/my-pkg/deno.json
@@ -0,0 +1,8 @@
+{
+ "name": "@scope/my-pkg",
+ "version": "1.0.0",
+ "exports": "./mod.ts",
+ "imports": {
+ "@denotest/add": "jsr:@denotest/add@1"
+ }
+}
diff --git a/tests/specs/workspaces/patch/workspace/my-pkg/mod.test.ts b/tests/specs/workspaces/patch/workspace/my-pkg/mod.test.ts
new file mode 100644
index 000000000..1c694298c
--- /dev/null
+++ b/tests/specs/workspaces/patch/workspace/my-pkg/mod.test.ts
@@ -0,0 +1,7 @@
+import { add } from "./mod.ts";
+
+Deno.test("add", () => {
+ if (add(1, 2) !== 3) {
+ throw new Error("fail");
+ }
+});
diff --git a/tests/specs/workspaces/patch/workspace/my-pkg/mod.ts b/tests/specs/workspaces/patch/workspace/my-pkg/mod.ts
new file mode 100644
index 000000000..11501ab39
--- /dev/null
+++ b/tests/specs/workspaces/patch/workspace/my-pkg/mod.ts
@@ -0,0 +1 @@
+export { add } from "@denotest/add";