diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-07-02 15:00:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-02 15:00:16 -0700 |
commit | c13b6d1413859d03b41b97d4c671fccfd388b2cc (patch) | |
tree | 503c5d2c51c71f3daa79950b6862b725e9211822 /tests | |
parent | d379c0b299411a847765e2879f8ed14bdb2d0298 (diff) |
feat(cli): Add `--frozen` flag to error out if lockfile is out of date (#24355)
Closes #18296.
Adds a `--frozen` (alias `--frozen-lockfile`) flag that errors out if
the lockfile is out of date. This is useful for running in CI (where an
out of date lockfile is usually a mistake) or to prevent accidental
changes in dependencies.

Diffstat (limited to 'tests')
22 files changed, 336 insertions, 1 deletions
diff --git a/tests/specs/lockfile/frozen_lockfile/__test__.jsonc b/tests/specs/lockfile/frozen_lockfile/__test__.jsonc new file mode 100644 index 000000000..76712a913 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/__test__.jsonc @@ -0,0 +1,157 @@ +{ + "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 + }, + { + // update the lockfile + "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" + } + ] + }, + "errors_if_creates_lockfile": { + "steps": [ + { + "args": [ + "eval", + "Deno.statSync('lock.json')" + ], + "output": "[WILDCARD]NotFound[WILDCARD]", + "exitCode": 1 + }, + { + "args": "run --frozen add.ts", + "output": "no_lockfile_run.out", + "exitCode": 1 + } + ] + }, + "non_analyzable_dynamic_npm": { + "steps": [ + { + "args": "cache add.ts", + "output": "[WILDCARD]" + }, + { + "args": "run --frozen sub-dynamic.ts", + "output": "frozen_new_dep_dynamic_npm.out", + "exitCode": 1 + } + ] + }, + "non_analyzable_dynamic_jsr": { + "steps": [ + { + "args": "cache add.ts", + "output": "[WILDCARD]" + }, + { + "args": "run --frozen --allow-net jsr-dynamic.ts", + "output": "frozen_new_dep_dynamic_jsr.out", + "exitCode": 1 + } + ] + }, + "non_analyzable_dynamic_http": { + "steps": [ + { + "args": "cache add.ts", + "output": "[WILDCARD]" + }, + { + "args": "run --frozen --allow-net http-dynamic.ts", + "output": "frozen_new_dep_dynamic_http.out", + "exitCode": 1 + } + ] + } + } +} diff --git a/tests/specs/lockfile/frozen_lockfile/add.ts b/tests/specs/lockfile/frozen_lockfile/add.ts new file mode 100644 index 000000000..ce70a43ec --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/add.ts @@ -0,0 +1,2 @@ +import { add } from "npm:@denotest/add@1"; +console.log(`1 + 2 = ${add(1, 2)}`); diff --git a/tests/specs/lockfile/frozen_lockfile/deno.json b/tests/specs/lockfile/frozen_lockfile/deno.json new file mode 100644 index 000000000..176354f98 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/deno.json @@ -0,0 +1,3 @@ +{ + "nodeModulesDir": true +} diff --git a/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_cache.out b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_cache.out new file mode 100644 index 000000000..bf6c03367 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_cache.out @@ -0,0 +1,11 @@ +error: The lockfile is out of date. Run `deno cache --frozen=false` or rerun with `--frozen=false` to update it. +changes: + 5 | - "npm:@denotest/add@1": "npm:@denotest/add@1.0.0" + 5 | + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0", + 6 | + "npm:@denotest/subtract@1": "npm:@denotest/subtract@1.0.0" +11 | - } +12 | + }, +13 | + "@denotest/subtract@1.0.0": { +14 | + "integrity": "[WILDCARD]", +15 | + "dependencies": {} +16 | + } diff --git a/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_dynamic_http.out b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_dynamic_http.out new file mode 100644 index 000000000..99c884e9c --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_dynamic_http.out @@ -0,0 +1,10 @@ +Download http://localhost:4545/welcome.ts +error: Uncaught (in promise) TypeError: The lockfile is out of date. Run `deno cache --frozen=false` or rerun with `--frozen=false` to update it. +changes: +14 | - "remote": {} +14 | + "remote": { +15 | + "http://localhost:4545/welcome.ts": "[WILDCARD]" +16 | + } +const _ = await import(scheme + "localhost:4545/welcome.ts"); + ^ + at [WILDCARD]
\ No newline at end of file diff --git a/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_dynamic_jsr.out b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_dynamic_jsr.out new file mode 100644 index 000000000..e77853ab2 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_dynamic_jsr.out @@ -0,0 +1,16 @@ +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 +error: Uncaught (in promise) TypeError: The lockfile is out of date. Run `deno cache --frozen=false` or rerun with `--frozen=false` to update it. +changes: + 5 | - "npm:@denotest/add@1": "npm:@denotest/add@1.0.0" + 5 | + "jsr:@denotest/add@1": "jsr:@denotest/add@1.0.0", + 6 | + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0" + 7 | + }, + 8 | + "jsr": { + 9 | + "@denotest/add@1.0.0": { +10 | + "integrity": "[WILDCARD]" +11 | + } +const { add } = await import(scheme + "@denotest/add@1"); + ^ + at [WILDCARD]
\ No newline at end of file diff --git a/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_dynamic_npm.out b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_dynamic_npm.out new file mode 100644 index 000000000..9b2efa462 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_dynamic_npm.out @@ -0,0 +1,15 @@ +Download http://localhost:4260/@denotest/subtract +error: Uncaught (in promise) TypeError: The lockfile is out of date. Run `deno cache --frozen=false` or rerun with `--frozen=false` to update it. +changes: + 5 | - "npm:@denotest/add@1": "npm:@denotest/add@1.0.0" + 5 | + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0", + 6 | + "npm:@denotest/subtract@1": "npm:@denotest/subtract@1.0.0" +11 | - } +12 | + }, +13 | + "@denotest/subtract@1.0.0": { +14 | + "integrity": "[WILDCARD]", +15 | + "dependencies": {} +16 | + } +const { subtract } = await import(scheme + "@denotest/subtract@1"); + ^ + at [WILDCARD] diff --git a/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_jsr_cache.out b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_jsr_cache.out new file mode 100644 index 000000000..bb523deff --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_jsr_cache.out @@ -0,0 +1,12 @@ +error: The lockfile is out of date. Run `deno cache --frozen=false` or rerun with `--frozen=false` to update it. +changes: + 5 | - "jsr:@denotest/add@1": "jsr:@denotest/add@1.0.0" + 6 | - }, + 7 | - "jsr": { + 5 | + "jsr:@denotest/add@0.2.0": "jsr:@denotest/add@0.2.0", + 6 | + "jsr:@denotest/add@1": "jsr:@denotest/add@1.0.0" + 7 | + }, + 8 | + "jsr": { + 9 | + "@denotest/add@0.2.0": { +10 | + "integrity": "[WILDCARD]" +11 | + }, diff --git a/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_jsr_run.out b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_jsr_run.out new file mode 100644 index 000000000..3a0d51678 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_jsr_run.out @@ -0,0 +1,14 @@ +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 --frozen=false` or rerun with `--frozen=false` to update it. +changes: + 5 | - "jsr:@denotest/add@1": "jsr:@denotest/add@1.0.0" + 6 | - }, + 7 | - "jsr": { + 5 | + "jsr:@denotest/add@0.2.0": "jsr:@denotest/add@0.2.0", + 6 | + "jsr:@denotest/add@1": "jsr:@denotest/add@1.0.0" + 7 | + }, + 8 | + "jsr": { + 9 | + "@denotest/add@0.2.0": { +10 | + "integrity": "[WILDCARD]" +11 | + }, diff --git a/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_run.out b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_run.out new file mode 100644 index 000000000..6dad6f6f4 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/frozen_new_dep_run.out @@ -0,0 +1,12 @@ +Download http://localhost:4260/@denotest/subtract +error: The lockfile is out of date. Run `deno cache --frozen=false` or rerun with `--frozen=false` to update it. +changes: + 5 | - "npm:@denotest/add@1": "npm:@denotest/add@1.0.0" + 5 | + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0", + 6 | + "npm:@denotest/subtract@1": "npm:@denotest/subtract@1.0.0" +11 | - } +12 | + }, +13 | + "@denotest/subtract@1.0.0": { +14 | + "integrity": "[WILDCARD]", +15 | + "dependencies": {} +16 | + } diff --git a/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed.out b/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed.out new file mode 100644 index 000000000..066aa2303 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed.out @@ -0,0 +1,25 @@ +Download http://localhost:4260/@denotest/bin +error: The lockfile is out of date. Run `deno cache --frozen=false` or rerun with `--frozen=false` to update it. +changes: + 5 | - "npm:@denotest/add@1": "npm:@denotest/add@1.0.0" + 5 | + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0", + 6 | + "npm:@denotest/bin@0.7.0": "npm:@denotest/bin@0.7.0" +11 | - } +12 | - } +13 | - }, +14 | - "remote": {} +12 | + }, +13 | + "@denotest/bin@0.7.0": { +14 | + "integrity": "[WILDCARD]", +15 | + "dependencies": {} +16 | + } +17 | + } +18 | + }, +19 | + "remote": {}, +20 | + "workspace": { +21 | + "packageJson": { +22 | + "dependencies": [ +23 | + "npm:@denotest/bin@0.7.0" +24 | + ] +25 | + } +26 | + } diff --git a/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed_install.out b/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed_install.out new file mode 100644 index 000000000..14530d573 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/frozen_package_json_changed_install.out @@ -0,0 +1,25 @@ +⚠️ `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 --frozen=false`, `deno install --frozen=false`, or rerun with `--frozen=false` to update it. +changes: + 5 | - "npm:@denotest/add@1": "npm:@denotest/add@1.0.0" + 5 | + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0", + 6 | + "npm:@denotest/bin@0.7.0": "npm:@denotest/bin@0.7.0" +11 | - } +12 | - } +13 | - }, +14 | - "remote": {} +12 | + }, +13 | + "@denotest/bin@0.7.0": { +14 | + "integrity": "[WILDCARD]", +15 | + "dependencies": {} +16 | + } +17 | + } +18 | + }, +19 | + "remote": {}, +20 | + "workspace": { +21 | + "packageJson": { +22 | + "dependencies": [ +23 | + "npm:@denotest/bin@0.7.0" +24 | + ] +25 | + } +26 | + } diff --git a/tests/specs/lockfile/frozen_lockfile/http-dynamic.ts b/tests/specs/lockfile/frozen_lockfile/http-dynamic.ts new file mode 100644 index 000000000..bb773e3c9 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/http-dynamic.ts @@ -0,0 +1,2 @@ +const scheme = "http://"; +const _ = await import(scheme + "localhost:4545/welcome.ts"); diff --git a/tests/specs/lockfile/frozen_lockfile/jsr-dynamic.ts b/tests/specs/lockfile/frozen_lockfile/jsr-dynamic.ts new file mode 100644 index 000000000..95d4dd02c --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/jsr-dynamic.ts @@ -0,0 +1,2 @@ +const scheme = "jsr:"; +const { add } = await import(scheme + "@denotest/add@1"); diff --git a/tests/specs/lockfile/frozen_lockfile/jsr.ts b/tests/specs/lockfile/frozen_lockfile/jsr.ts new file mode 100644 index 000000000..1ffb7dc70 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/jsr.ts @@ -0,0 +1 @@ +import { add } from "jsr:@denotest/add@1"; diff --git a/tests/specs/lockfile/frozen_lockfile/jsr2.ts b/tests/specs/lockfile/frozen_lockfile/jsr2.ts new file mode 100644 index 000000000..bfc0bf48f --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/jsr2.ts @@ -0,0 +1,2 @@ +import { sum } from "jsr:@denotest/add@0.2.0"; +console.log(`1 + 2 = ${sum(1, 2)}`); diff --git a/tests/specs/lockfile/frozen_lockfile/no_lockfile_run.out b/tests/specs/lockfile/frozen_lockfile/no_lockfile_run.out new file mode 100644 index 000000000..2ae84b110 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/no_lockfile_run.out @@ -0,0 +1,20 @@ +Download http://localhost:4260/@denotest/add +error: The lockfile is out of date. Run `deno cache --frozen=false` or rerun with `--frozen=false` to update it. +changes: + 1 | - + 1 | +{ + 2 | + "version": "3", + 3 | + "packages": { + 4 | + "specifiers": { + 5 | + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0" + 6 | + }, + 7 | + "npm": { + 8 | + "@denotest/add@1.0.0": { + 9 | + "integrity": "[WILDCARD]", +10 | + "dependencies": {} +11 | + } +12 | + } +13 | + }, +14 | + "remote": {} +15 | +} +16 | + diff --git a/tests/specs/lockfile/frozen_lockfile/package.json b/tests/specs/lockfile/frozen_lockfile/package.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/specs/lockfile/frozen_lockfile/sub-dynamic.ts b/tests/specs/lockfile/frozen_lockfile/sub-dynamic.ts new file mode 100644 index 000000000..255dec2b2 --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/sub-dynamic.ts @@ -0,0 +1,2 @@ +const scheme = "npm:"; +const { subtract } = await import(scheme + "@denotest/subtract@1"); diff --git a/tests/specs/lockfile/frozen_lockfile/sub.ts b/tests/specs/lockfile/frozen_lockfile/sub.ts new file mode 100644 index 000000000..f212b290d --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/sub.ts @@ -0,0 +1,2 @@ +import { subtract } from "npm:@denotest/subtract@1"; +console.log(`3 - 2 = ${subtract(3, 2)}`); diff --git a/tests/specs/lockfile/frozen_lockfile/update_lockfile.out b/tests/specs/lockfile/frozen_lockfile/update_lockfile.out new file mode 100644 index 000000000..0eebd114e --- /dev/null +++ b/tests/specs/lockfile/frozen_lockfile/update_lockfile.out @@ -0,0 +1,2 @@ +Download http://localhost:4260/@denotest/subtract/1.0.0.tgz +Initialize @denotest/subtract@1.0.0 diff --git a/tests/specs/npm/npmrc_not_next_to_package_json/main.out b/tests/specs/npm/npmrc_not_next_to_package_json/main.out index 933d44f1c..8f42fb6d8 100644 --- a/tests/specs/npm/npmrc_not_next_to_package_json/main.out +++ b/tests/specs/npm/npmrc_not_next_to_package_json/main.out @@ -4,4 +4,3 @@ [WILDCARD] Download http://localhost:4260/@denotest/esm-basic/1.0.0.tgz Initialize @denotest/esm-basic@1.0.0 -[WILDCARD] |