-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
123 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,129 @@ | ||
import { all, cmd, fs } from "@chiezo/amber"; | ||
import { afterEach, beforeEach, describe, it } from "@std/testing/bdd"; | ||
import { assertSpyCallArg } from "@std/testing/mock"; | ||
import { collect } from "./mod.ts"; | ||
import { assertEquals, assertExists } from "@std/assert"; | ||
import dedent from "dedent"; | ||
|
||
Deno.test("Molt", { ignore: true }, async () => { | ||
cmd.stub("git"); | ||
all(cmd, fs).mock(); | ||
const MOD_TS = dedent` | ||
import "jsr:@luca/flag@1.0.0"; | ||
`; | ||
|
||
const deps = await collect({ | ||
config: "deno.json", | ||
lock: "deno.lock", | ||
}); | ||
const DENO_JSON = dedent` | ||
{ | ||
"imports": { | ||
"@luca/flag": "jsr:@luca/flag@^1.0.0", | ||
} | ||
} | ||
`; | ||
|
||
for (const dep of deps) { | ||
const update = await dep.check(); | ||
if (update) { | ||
await update.write(); | ||
await update.commit(); | ||
const DENO_LOCK = dedent` | ||
{ | ||
"version": "3", | ||
"packages": { | ||
"specifiers": { | ||
"jsr:@luca/flag@^1.0.0": "jsr:@luca/flag@1.0.0" | ||
}, | ||
"jsr": { | ||
"@luca/flag@1.0.0": { | ||
"integrity": "1c76cf54839a86d0929a619c61bd65bb73d7d8a4e31788e48c720dbc46c5d546" | ||
} | ||
} | ||
}, | ||
"remote": {}, | ||
"workspace": { | ||
"dependencies": [ | ||
"jsr:@luca/flag@^1.0.0" | ||
] | ||
} | ||
} | ||
`; | ||
|
||
describe("core", () => { | ||
let git: cmd.Stub<"git">; | ||
|
||
beforeEach(async () => { | ||
git = cmd.stub("git"); | ||
all(cmd, fs).mock(); | ||
await Promise.all([ | ||
Deno.writeTextFile("mod.ts", MOD_TS), | ||
Deno.writeTextFile("deno.json", DENO_JSON), | ||
Deno.writeTextFile("deno.lock", DENO_LOCK), | ||
]); | ||
}); | ||
|
||
afterEach(() => all(cmd, fs).dispose()); | ||
|
||
it("should update dependencies in a module", async () => { | ||
const deps = await collect({ source: ["mod.ts"] }); | ||
assertEquals(deps.length, 1); | ||
const [dep] = deps; | ||
const update = await dep.check(); | ||
assertExists(update); | ||
assertEquals(update.dep.name, "@luca/flag"); | ||
await update.write(); | ||
assertEquals(await Deno.readTextFile("deno.json"), DENO_JSON); | ||
assertEquals(await Deno.readTextFile("deno.lock"), DENO_LOCK); | ||
assertEquals( | ||
await Deno.readTextFile("mod.ts"), | ||
`import "jsr:@luca/flag@1.0.1";`, | ||
); | ||
await update.commit(); | ||
assertSpyCallArg(git, 0, 1, { | ||
args: [ | ||
"commit", | ||
"-m", | ||
"bump @luca/flag from 1.0.0 to 1.0.1", | ||
"mod.ts", | ||
], | ||
lock: undefined, | ||
}); | ||
}); | ||
|
||
it("should update dependencies in a configuration", async () => { | ||
const deps = await collect({ config: "deno.json", lock: "deno.lock" }); | ||
assertEquals(deps.length, 1); | ||
const [dep] = deps; | ||
const update = await dep.check(); | ||
assertExists(update); | ||
assertEquals(update.dep.name, "@luca/flag"); | ||
await update.write(); | ||
assertEquals(await Deno.readTextFile("mod.ts"), MOD_TS); | ||
assertEquals(await Deno.readTextFile("deno.json"), DENO_JSON); | ||
assertEquals( | ||
await Deno.readTextFile("deno.lock"), | ||
dedent` | ||
{ | ||
"version": "3", | ||
"packages": { | ||
"specifiers": { | ||
"jsr:@luca/flag@^1.0.0": "jsr:@luca/flag@1.0.1" | ||
}, | ||
"jsr": { | ||
"@luca/flag@1.0.1": { | ||
"integrity": "dce7eb4159b1bdb1606fe05c2e5388dcff5ae3b0b84184b934bc623143742408" | ||
} | ||
} | ||
}, | ||
"remote": {}, | ||
"workspace": { | ||
"dependencies": [ | ||
"jsr:@luca/flag@^1.0.0" | ||
] | ||
} | ||
} | ||
` + "\n", | ||
); | ||
await update.commit(); | ||
assertSpyCallArg(git, 0, 1, { | ||
args: [ | ||
"commit", | ||
"-m", | ||
"bump @luca/flag from 1.0.0 to 1.0.1", | ||
"deno.json", | ||
"deno.lock", | ||
], | ||
lock: "deno.lock", | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters