Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Add --frozen flag to error out if lockfile is out of date #24355

Merged
merged 16 commits into from
Jul 2, 2024
Prev Previous commit
Next Next commit
Add spec tests
  • Loading branch information
nathanwhit committed Jun 29, 2024
commit 78ace03297999b6e9c525ec98614376068ad3435
101 changes: 101 additions & 0 deletions tests/specs/lockfile/frozen_lockfile/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 1,101 @@
{
"tempDir": true,
"tests": {
"error_with_new_npm_dep": {
"steps": [
{
"args": "cache add.ts",
"output": "[WILDCARD]"
},
{
// sub.ts imports from an npm package
// that's not in the lockfile
"args": "run --frozen sub.ts",
"output": "frozen_new_dep_run.out",
"exitCode": 1
},
{
"args": "cache --frozen sub.ts",
"output": "frozen_new_dep_cache.out",
"exitCode": 1
},
{
// now fix it
"args": "cache sub.ts",
"output": "update_lockfile.out"
},
{
"args": "run --frozen sub.ts",
"output": "3 - 2 = 1\n"
}
]
},
"error_with_new_jsr_dep": {
"steps": [
{
"args": "cache jsr.ts",
"output": "[WILDCARD]"
},
{
"args": "run --frozen jsr2.ts",
"output": "frozen_new_dep_jsr_run.out",
"exitCode": 1
},
{
"args": "cache --frozen jsr2.ts",
"output": "frozen_new_dep_jsr_cache.out",
"exitCode": 1
},
{
// update the lockfile
"args": "cache jsr2.ts",
"output": ""
},
{
"args": "run --frozen jsr2.ts",
"output": "1 2 = 3\n"
}
]
},
"error_when_package_json_changed": {
"steps": [
{
"args": "cache add.ts",
"output": "[WILDCARD]"
},
{
"args": [
"eval",
"Deno.writeTextFileSync(\"package.json\", JSON.stringify({ dependencies: { \"@denotest/bin\": \"0.7.0\" } }))"
],
"output": ""
},
{
"args": "cache --frozen add.ts",
"output": "frozen_package_json_changed.out",
"exitCode": 1
},
{
"envs": {
"DENO_FUTURE": "1"
},
"args": "install --frozen",
"output": "frozen_package_json_changed_install.out",
"exitCode": 1
}
]
},
"no_error_when_in_lockfile": {
"steps": [
{
"args": "cache add.ts",
"output": "[WILDCARD]"
},
{
"args": "run --frozen add.ts",
"output": "1 2 = 3\n"
}
]
}
}
}
2 changes: 2 additions & 0 deletions tests/specs/lockfile/frozen_lockfile/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
import { add } from "npm:@denotest/add@1";
console.log(`1 2 = ${add(1, 2)}`);
3 changes: 3 additions & 0 deletions tests/specs/lockfile/frozen_lockfile/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 1,3 @@
{
"nodeModulesDir": true
}
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
error: The lockfile is out of date. Run `deno cache` to update it.
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
error: The lockfile is out of date. Run `deno cache` to update it.
Original file line number Diff line number Diff line change
@@ -0,0 1,3 @@
Download http://127.0.0.1:4250/@denotest/add/0.2.0_meta.json
Download http://127.0.0.1:4250/@denotest/add/0.2.0/mod.ts
error: The lockfile is out of date. Run `deno cache` to update it.
2 changes: 2 additions & 0 deletions tests/specs/lockfile/frozen_lockfile/frozen_new_dep_run.out
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
Download http://localhost:4260/@denotest/subtract
error: The lockfile is out of date. Run `deno cache` to update it.
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
Download http://localhost:4260/@denotest/bin
error: The lockfile is out of date. Run `deno cache` to update it.
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
error: The lockfile is out of date. Run `deno cache` or `deno install` to update it.
1 change: 1 addition & 0 deletions tests/specs/lockfile/frozen_lockfile/jsr.ts
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
import { add } from "jsr:@denotest/add@1";
2 changes: 2 additions & 0 deletions tests/specs/lockfile/frozen_lockfile/jsr2.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
import { sum } from "jsr:@denotest/[email protected]";
console.log(`1 2 = ${sum(1, 2)}`);
1 change: 1 addition & 0 deletions tests/specs/lockfile/frozen_lockfile/package.json
Original file line number Diff line number Diff line change
@@ -0,0 1 @@
{}
2 changes: 2 additions & 0 deletions tests/specs/lockfile/frozen_lockfile/sub.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
import { subtract } from "npm:@denotest/subtract@1";
console.log(`3 - 2 = ${subtract(3, 2)}`);
2 changes: 2 additions & 0 deletions tests/specs/lockfile/frozen_lockfile/update_lockfile.out
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
Download http://localhost:4260/@denotest/subtract/1.0.0.tgz
Initialize @denotest/[email protected]