Skip to content

Commit

Permalink
refactor(test): rename tests/ as test/fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Oct 21, 2023
1 parent a3bf60e commit 470f0bd
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 56 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"exclude": ["CHANGELOG.md"]
},
"lint": {
"exclude": ["tests/"],
"exclude": ["test/"],
"rules": {
"include": [
"no-sync-fn-in-async-fn"
Expand Down
30 changes: 16 additions & 14 deletions lib/file_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import { URI } from "./uri.ts";
describe("collect", () => {
it("direct import", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect("./tests/direct-import/mod.ts"),
await DependencyUpdate.collect("./test/fixtures/direct-import/mod.ts"),
);
assertEquals(results.length, 2);
});

it("import map", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect(
"./tests/import-map/mod.ts",
{ importMap: "./tests/import-map/deno.json" },
"./test/fixtures/import-map/mod.ts",
{ importMap: "./test/fixtures/import-map/deno.json" },
),
);
assertEquals(results.length, 2);
Expand All @@ -44,8 +44,8 @@ describe("collect", () => {
it("import map with no resolve", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect(
"./tests/import-map-no-resolve/mod.ts",
{ importMap: "./tests/import-map-no-resolve/deno.json" },
"./test/fixtures/import-map-no-resolve/mod.ts",
{ importMap: "./test/fixtures/import-map-no-resolve/deno.json" },
),
);
assertEquals(results.length, 1);
Expand Down Expand Up @@ -75,32 +75,34 @@ describe("writeAll", () => {

it("direct import", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect("./tests/direct-import/mod.ts"),
await DependencyUpdate.collect("./test/fixtures/direct-import/mod.ts"),
);
FileUpdate.writeAll(results);
assertExists(output.get(URI.from("tests/direct-import/mod.ts")));
assertExists(output.get(URI.from("tests/direct-import/lib.ts")));
assertExists(output.get(URI.from("test/fixtures/direct-import/mod.ts")));
assertExists(output.get(URI.from("test/fixtures/direct-import/lib.ts")));
});

it("import map", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect(
"./tests/import-map/mod.ts",
{ importMap: "./tests/import-map/deno.json" },
"./test/fixtures/import-map/mod.ts",
{ importMap: "./test/fixtures/import-map/deno.json" },
),
);
FileUpdate.writeAll(results);
assertExists(output.get(URI.from("tests/import-map/deno.json")));
assertExists(output.get(URI.from("test/fixtures/import-map/deno.json")));
});

it("import map with no resolve", async () => {
const results = FileUpdate.collect(
await DependencyUpdate.collect(
"./tests/import-map-no-resolve/mod.ts",
{ importMap: "./tests/import-map-no-resolve/deno.json" },
"./test/fixtures/import-map-no-resolve/mod.ts",
{ importMap: "./test/fixtures/import-map-no-resolve/deno.json" },
),
);
FileUpdate.writeAll(results);
assertExists(output.get(URI.from("tests/import-map-no-resolve/mod.ts")));
assertExists(
output.get(URI.from("test/fixtures/import-map-no-resolve/mod.ts")),
);
});
});
22 changes: 12 additions & 10 deletions lib/git_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ describe("commitAll()", () => {
let readTextFileSyncStub: Stub;

beforeAll(async () => {
updates = await DependencyUpdate.collect("./tests/direct-import/mod.ts");
updates = await DependencyUpdate.collect(
"./test/fixtures/direct-import/mod.ts",
);
writeTextFileSyncStub = stub(
Deno,
"writeTextFileSync",
Expand Down Expand Up @@ -72,8 +74,8 @@ describe("commitAll()", () => {
beforeEach(() => {
for (
const file of [
"./tests/direct-import/mod.ts",
"./tests/direct-import/lib.ts",
"./test/fixtures/direct-import/mod.ts",
"./test/fixtures/direct-import/lib.ts",
]
) {
const content = readTextFileSyncOriginal(file);
Expand Down Expand Up @@ -107,11 +109,11 @@ describe("commitAll()", () => {
assertArrayIncludes(
DenoCommandStub.commands,
[
"git add tests/direct-import/mod.ts",
"git add test/fixtures/direct-import/mod.ts",
'git commit -m "build(deps): update node-emoji"',
"git add tests/direct-import/mod.ts",
"git add test/fixtures/direct-import/mod.ts",
'git commit -m "build(deps): update deno.land/x/deno_graph"',
// "git add tests/direct-import/mod.ts tests/direct-import/lib.ts",
// "git add test/fixtures/direct-import/mod.ts test/fixtures/direct-import/lib.ts",
'git commit -m "build(deps): update deno.land/std"',
],
);
Expand All @@ -126,10 +128,10 @@ describe("commitAll()", () => {
assertArrayIncludes(
DenoCommandStub.commands,
[
"git add tests/direct-import/mod.ts",
'git commit -m "build(deps): update tests/direct-import/mod.ts"',
"git add tests/direct-import/lib.ts",
'git commit -m "build(deps): update tests/direct-import/lib.ts"',
"git add test/fixtures/direct-import/mod.ts",
'git commit -m "build(deps): update test/fixtures/direct-import/mod.ts"',
"git add test/fixtures/direct-import/lib.ts",
'git commit -m "build(deps): update test/fixtures/direct-import/lib.ts"',
],
);
});
Expand Down
39 changes: 24 additions & 15 deletions lib/import_map_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,34 @@ describe("readFromJson()", () => {
assertEquals(importMap, undefined);
await Deno.remove(f);
});
it("tests/import-map/deno.json", async () => {
it("test/fixtures/import-map/deno.json", async () => {
const importMap = await ImportMap.readFromJson(
new URL("../tests/import-map/deno.json", import.meta.url),
new URL("../test/fixtures/import-map/deno.json", import.meta.url),
);
assertExists(importMap);
});
it("tests/import-map-referred/import_map.json", async () => {
it("test/fixtures/import-map-referred/import_map.json", async () => {
const importMap = await ImportMap.readFromJson(
new URL("../tests/import-map-referred/deno.json", import.meta.url),
new URL(
"../test/fixtures/import-map-referred/deno.json",
import.meta.url,
),
);
assertExists(importMap);
assertEquals(
importMap.specifier,
URI.from("./tests/import-map-referred/import_map.json"),
URI.from("./test/fixtures/import-map-referred/import_map.json"),
);
});
});

describe("resolve()", () => {
it("resolve specifiers in import maps", async () => {
const importMap = await ImportMap.readFromJson(
new URL("../tests/import-map/deno.json", import.meta.url),
new URL("../test/fixtures/import-map/deno.json", import.meta.url),
);
assertExists(importMap);
const referrer = URI.from("tests/import-map/mod.ts");
const referrer = URI.from("test/fixtures/import-map/mod.ts");
assertEquals(
importMap.resolve("std/version.ts", referrer),
{
Expand Down Expand Up @@ -67,19 +70,19 @@ describe("resolve()", () => {
assertEquals(
importMap.resolve("/lib.ts", referrer),
{
specifier: URI.from("tests/import-map/lib.ts"),
specifier: URI.from("test/fixtures/import-map/lib.ts"),
},
);
});
it("do not resolve an url", async () => {
const importMap = await ImportMap.readFromJson(
new URL(
"../tests/import-map-no-resolve/deno.json",
"../test/fixtures/import-map-no-resolve/deno.json",
import.meta.url,
),
);
assertExists(importMap);
const referrer = URI.from("tests/import-map-no-resolve/deps.ts");
const referrer = URI.from("test/fixtures/import-map-no-resolve/deps.ts");
assertEquals(
importMap.resolve(
"https://deno.land/std@0.171.0/testing/asserts.ts",
Expand All @@ -90,10 +93,13 @@ describe("resolve()", () => {
});
it("resolve specifiers in a referred import map", async () => {
const importMap = await ImportMap.readFromJson(
new URL("../tests/import-map-referred/deno.json", import.meta.url),
new URL(
"../test/fixtures/import-map-referred/deno.json",
import.meta.url,
),
);
assertExists(importMap);
const referrer = URI.from("tests/import-map-referred/mod.ts");
const referrer = URI.from("test/fixtures/import-map-referred/mod.ts");
assertEquals(
importMap.resolve("dax", referrer),
{
Expand All @@ -109,15 +115,18 @@ describe("resolveSimple()", () => {
let importMap: ImportMap;
beforeAll(async () => {
const maybe = await ImportMap.readFromJson(
new URL("../tests/import-map/deno.json", import.meta.url),
new URL("../test/fixtures/import-map/deno.json", import.meta.url),
);
assertExists(maybe);
importMap = maybe;
});
it("resolve an absolute path", () => {
assertEquals(
importMap.resolveSimple("/lib.ts", URI.from("tests/import-map/mod.ts")),
URI.from("tests/import-map/lib.ts"),
importMap.resolveSimple(
"/lib.ts",
URI.from("test/fixtures/import-map/mod.ts"),
),
URI.from("test/fixtures/import-map/lib.ts"),
);
});
});
32 changes: 16 additions & 16 deletions lib/update_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("_create", () => {
specifier: "https://deno.land/std@0.1.0/version.ts",
// deno-lint-ignore no-explicit-any
} as any,
}, URI.from("tests/direct-import/mod.ts"));
}, URI.from("test/fixtures/direct-import/mod.ts"));
assertExists(update);
});
it("https://deno.land/std - no semver", async () => {
Expand All @@ -27,7 +27,7 @@ describe("_create", () => {
specifier: "https://deno.land/std/version.ts",
// deno-lint-ignore no-explicit-any
} as any,
}, URI.from("tests/direct-import/mod.ts"));
}, URI.from("test/fixtures/direct-import/mod.ts"));
assertEquals(update, undefined);
});
it("https://deno.land/x/deno_graph", async () => {
Expand All @@ -37,7 +37,7 @@ describe("_create", () => {
specifier: "https://deno.land/x/deno_graph@0.1.0/mod.ts",
// deno-lint-ignore no-explicit-any
} as any,
}, URI.from("tests/direct-import/mod.ts"));
}, URI.from("test/fixtures/direct-import/mod.ts"));
assertExists(update);
});
it("npm:node-emoji", async () => {
Expand All @@ -47,7 +47,7 @@ describe("_create", () => {
specifier: "npm:node-emoji@1.0.0",
// deno-lint-ignore no-explicit-any
} as any,
}, URI.from("tests/direct-import/mod.ts"));
}, URI.from("test/fixtures/direct-import/mod.ts"));
assertExists(update);
});
});
Expand All @@ -56,7 +56,7 @@ describe("_create - with import map", () => {
let importMap: ImportMap;
beforeAll(async () => {
importMap = (await ImportMap.readFromJson(
new URL("../tests/import-map/deno.json", import.meta.url),
new URL("../test/fixtures/import-map/deno.json", import.meta.url),
))!;
});
it("std/version.ts", async () => {
Expand All @@ -68,7 +68,7 @@ describe("_create - with import map", () => {
// deno-lint-ignore no-explicit-any
} as any,
},
URI.from("tests/import-map/mod.ts"),
URI.from("test/fixtures/import-map/mod.ts"),
{ importMap },
);
assertExists(update);
Expand All @@ -81,9 +81,9 @@ describe("_create - with import map", () => {
path: "/version.ts",
specifier: "https://deno.land/std@0.200.0/version.ts",
code: { specifier: "std/version.ts" },
referrer: URI.from("tests/import-map/mod.ts"),
referrer: URI.from("test/fixtures/import-map/mod.ts"),
map: {
source: URI.from("tests/import-map/deno.json"),
source: URI.from("test/fixtures/import-map/deno.json"),
from: "std/",
to: "https://deno.land/std@0.200.0/",
},
Expand All @@ -94,15 +94,15 @@ describe("_create - with import map", () => {
describe("collect", () => {
it("direct import", async () => {
const updates = await DependencyUpdate.collect(
"./tests/direct-import/mod.ts",
"./test/fixtures/direct-import/mod.ts",
);
assertEquals(updates.length, 4);
});
it("import map", async () => {
const updates = await DependencyUpdate.collect(
"./tests/import-map/mod.ts",
"./test/fixtures/import-map/mod.ts",
{
importMap: "./tests/import-map/deno.json",
importMap: "./test/fixtures/import-map/deno.json",
},
);
assertEquals(updates.length, 4);
Expand All @@ -114,9 +114,9 @@ describe("applyToModule", () => {
let content: string;
beforeAll(async () => {
updates = await DependencyUpdate.collect(
"./tests/direct-import/mod.ts",
"./test/fixtures/direct-import/mod.ts",
);
content = await Deno.readTextFile("./tests/direct-import/mod.ts");
content = await Deno.readTextFile("./test/fixtures/direct-import/mod.ts");
});
it("https://deno.land/x/deno_graph", () => {
const update = updates.find((update) =>
Expand Down Expand Up @@ -147,10 +147,10 @@ describe("applyToImportMap", () => {
let content: string;
beforeAll(async () => {
updates = await DependencyUpdate.collect(
"./tests/import-map/mod.ts",
{ importMap: "tests/import-map/deno.json" },
"./test/fixtures/import-map/mod.ts",
{ importMap: "test/fixtures/import-map/deno.json" },
);
content = await Deno.readTextFile("tests/import-map/deno.json");
content = await Deno.readTextFile("test/fixtures/import-map/deno.json");
});
it("deno_graph", () => {
const update = updates.find((update) =>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 470f0bd

Please sign in to comment.