From 8754a01d43782654c3d32945f6d58f7a40c01b69 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 14 Jul 2024 13:22:43 -0400 Subject: [PATCH] fix(init): use bare specifier for `jsr:@std/assert` (#24581) Closes #24580 --- cli/tools/init/mod.rs | 16 +++++++++----- tests/integration/init_tests.rs | 3 ++- .../registry/jsr/@std/assert/1.0.0/assert.ts | 4 ++++ .../jsr/@std/assert/1.0.0/assert_equals.ts | 9 ++++++++ tests/registry/jsr/@std/assert/1.0.0/fail.ts | 5 +++++ tests/registry/jsr/@std/assert/1.0.0/mod.ts | 22 +++++++++++++++++++ .../registry/jsr/@std/assert/1.0.0_meta.json | 8 +++++++ tests/registry/jsr/@std/assert/meta.json | 3 ++- tests/specs/init/lib/test.out | 10 ++++----- 9 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 tests/registry/jsr/@std/assert/1.0.0/assert.ts create mode 100644 tests/registry/jsr/@std/assert/1.0.0/assert_equals.ts create mode 100644 tests/registry/jsr/@std/assert/1.0.0/fail.ts create mode 100644 tests/registry/jsr/@std/assert/1.0.0/mod.ts create mode 100644 tests/registry/jsr/@std/assert/1.0.0_meta.json diff --git a/cli/tools/init/mod.rs b/cli/tools/init/mod.rs index b043ab2c4b..bc83bfa2bf 100644 --- a/cli/tools/init/mod.rs +++ b/cli/tools/init/mod.rs @@ -39,7 +39,7 @@ pub fn init_project(init_flags: InitFlags) -> Result<(), AnyError> { create_file( &dir, "mod_test.ts", - r#"import { assertEquals } from "jsr:@std/assert"; + r#"import { assertEquals } from "@std/assert"; import { add } from "./mod.ts"; Deno.test(function addTest() { @@ -53,11 +53,14 @@ Deno.test(function addTest() { "deno.json", &json!({ "name": project_name, - "version": "1.0.0", - "exports": "./mod.ts", + "version": "0.1.0", "tasks": { "dev": "deno test --watch mod.ts" - } + }, + "imports": { + "@std/assert": "jsr:@std/assert@1" + }, + "exports": "./mod.ts" }), )?; } else { @@ -77,7 +80,7 @@ if (import.meta.main) { create_file( &dir, "main_test.ts", - r#"import { assertEquals } from "jsr:@std/assert"; + r#"import { assertEquals } from "@std/assert"; import { add } from "./main.ts"; Deno.test(function addTest() { @@ -92,6 +95,9 @@ Deno.test(function addTest() { &json!({ "tasks": { "dev": "deno run --watch main.ts" + }, + "imports": { + "@std/assert": "jsr:@std/assert@1" } }), )?; diff --git a/tests/integration/init_tests.rs b/tests/integration/init_tests.rs index d2a9fa59bc..65a57eeea4 100644 --- a/tests/integration/init_tests.rs +++ b/tests/integration/init_tests.rs @@ -81,7 +81,8 @@ fn init_subcommand_with_dir_arg() { let output = context .new_command() .env("NO_COLOR", "1") - .args("test my_dir/main_test.ts") + .current_dir("my_dir") + .args("test main_test.ts") .split_output() .run(); diff --git a/tests/registry/jsr/@std/assert/1.0.0/assert.ts b/tests/registry/jsr/@std/assert/1.0.0/assert.ts new file mode 100644 index 0000000000..8c20c347ac --- /dev/null +++ b/tests/registry/jsr/@std/assert/1.0.0/assert.ts @@ -0,0 +1,4 @@ +// deno-lint-ignore-file +export function assert(expr: unknown) { + return true; +} diff --git a/tests/registry/jsr/@std/assert/1.0.0/assert_equals.ts b/tests/registry/jsr/@std/assert/1.0.0/assert_equals.ts new file mode 100644 index 0000000000..bd58194d01 --- /dev/null +++ b/tests/registry/jsr/@std/assert/1.0.0/assert_equals.ts @@ -0,0 +1,9 @@ +// deno-lint-ignore-file +export function assertEquals( + actual: T, + expected: T, + msg?: string, + options: { formatter?: (value: unknown) => string } = {}, +) { + return true; +} diff --git a/tests/registry/jsr/@std/assert/1.0.0/fail.ts b/tests/registry/jsr/@std/assert/1.0.0/fail.ts new file mode 100644 index 0000000000..6c21edda54 --- /dev/null +++ b/tests/registry/jsr/@std/assert/1.0.0/fail.ts @@ -0,0 +1,5 @@ +// deno-lint-ignore-file + +export function fail() { + return true; +} diff --git a/tests/registry/jsr/@std/assert/1.0.0/mod.ts b/tests/registry/jsr/@std/assert/1.0.0/mod.ts new file mode 100644 index 0000000000..fdcb56c8cf --- /dev/null +++ b/tests/registry/jsr/@std/assert/1.0.0/mod.ts @@ -0,0 +1,22 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +/** A library of assertion functions. + * If the assertion is false an `AssertionError` will be thrown which will + * result in pretty-printed diff of failing assertion. + * + * This module is browser compatible, but do not rely on good formatting of + * values for AssertionError messages in browsers. + * + * ```ts + * import { assert } from "@std/assert/assert"; + * + * assert("I am truthy"); // Doesn't throw + * assert(false); // Throws `AssertionError` + * ``` + * + * @module + */ + +export * from "./assert_equals.ts"; +export * from "./assert.ts"; +export * from "./fail.ts"; diff --git a/tests/registry/jsr/@std/assert/1.0.0_meta.json b/tests/registry/jsr/@std/assert/1.0.0_meta.json new file mode 100644 index 0000000000..3ca2db93a6 --- /dev/null +++ b/tests/registry/jsr/@std/assert/1.0.0_meta.json @@ -0,0 +1,8 @@ +{ + "exports": { + ".": "./mod.ts", + "./assert": "./assert.ts", + "./assert-equals": "./assert-equals.ts", + "./fail": "./fail.ts" + } +} diff --git a/tests/registry/jsr/@std/assert/meta.json b/tests/registry/jsr/@std/assert/meta.json index 4bb721c891..419b83587f 100644 --- a/tests/registry/jsr/@std/assert/meta.json +++ b/tests/registry/jsr/@std/assert/meta.json @@ -1,8 +1,9 @@ { "scope": "std", "name": "assert", - "latest": "0.220.1", + "latest": "1.0.0", "versions": { + "1.0.0": {}, "0.220.1": {} } } diff --git a/tests/specs/init/lib/test.out b/tests/specs/init/lib/test.out index 0b225a52bb..b4f9823a9d 100644 --- a/tests/specs/init/lib/test.out +++ b/tests/specs/init/lib/test.out @@ -1,10 +1,10 @@ Download http://127.0.0.1:4250/@std/assert/meta.json -Download http://127.0.0.1:4250/@std/assert/0.220.1_meta.json +Download http://127.0.0.1:4250/@std/assert/1.0.0_meta.json [UNORDERED_START] -Download http://127.0.0.1:4250/@std/assert/0.220.1/mod.ts -Download http://127.0.0.1:4250/@std/assert/0.220.1/assert_equals.ts -Download http://127.0.0.1:4250/@std/assert/0.220.1/assert.ts -Download http://127.0.0.1:4250/@std/assert/0.220.1/fail.ts +Download http://127.0.0.1:4250/@std/assert/1.0.0/mod.ts +Download http://127.0.0.1:4250/@std/assert/1.0.0/assert_equals.ts +Download http://127.0.0.1:4250/@std/assert/1.0.0/assert.ts +Download http://127.0.0.1:4250/@std/assert/1.0.0/fail.ts [UNORDERED_END] Check file:///[WILDLINE]/mod_test.ts running 1 test from ./mod_test.ts