-
Notifications
You must be signed in to change notification settings - Fork 12
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
13 changed files
with
384 additions
and
54 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,6 +1,6 @@ | ||
#!/usr/bin/env -S pkgx +npm deno run --allow-env --allow-read --allow-write --allow-net --allow-run | ||
|
||
import { build, emptyDir } from "https://deno.land/x/dnt@0.38.1/mod.ts"; | ||
import { build, emptyDir } from "https://deno.land/x/dnt@0.39.0/mod.ts"; | ||
import SemVer from "../src/utils/semver.ts"; | ||
|
||
await emptyDir("./dist"); | ||
|
@@ -33,7 +33,9 @@ await build({ | |
mappings: { | ||
"https://deno.land/x/[email protected]/src/index.ts": "is-what", | ||
"https://deno.land/x/[email protected]/mod.ts": "outdent", | ||
"./src/utils/flock.deno.ts": "./src/utils/flock.node.ts" | ||
"./src/utils/flock.deno.ts": "./src/utils/flock.node.ts", | ||
"./src/hooks/useSyncCache.ts": "./src/hooks/useSyncCache.node.ts", | ||
"./src/hooks/useSyncCache.test.ts": "./src/hooks/useCache.test.ts" // no other easy way to skip the test | ||
}, | ||
package: { | ||
name: "libpkgx", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
}, | ||
"pkgx": "deno^1.33.3 npm", | ||
"tasks": { | ||
"test": "deno test --parallel --unstable --allow-env --allow-read --allow-net=dist.pkgx.dev,github.com,codeload.github.com --allow-write --allow-run=tar,uname,/bin/sh,foo,'C:\\Windows\\system32\\cmd.exe'", | ||
"test": "deno test --parallel --unstable --allow-env --allow-read --allow-net=dist.pkgx.dev,github.com,codeload.github.com,objects.githubusercontent.com --allow-write --allow-run=tar,uname,/bin/sh,foo,'C:\\Windows\\system32\\cmd.exe' --allow-ffi", | ||
"typecheck": "deno check --unstable ./mod.ts", | ||
"dnt": ".github/deno-to-node.ts" | ||
}, | ||
|
@@ -26,7 +26,7 @@ | |
}, | ||
"imports": { | ||
"is-what": "https://deno.land/x/[email protected]/src/index.ts", | ||
"deno/": "https://deno.land/std@0.204.0/", | ||
"deno/": "https://deno.land/std@0.196.0/", | ||
"outdent": "https://deno.land/x/[email protected]/mod.ts" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,13 +8,13 @@ import * as outdent from "https://deno.land/x/[email protected]/mod.ts" | |
export { outdent } | ||
|
||
// importing super specifically to reduce final npm bundle size | ||
import * as crypto from "https://deno.land/std@0.204.0/crypto/mod.ts" | ||
import { moveSync } from "https://deno.land/std@0.204.0/fs/move.ts" | ||
import { readLines } from "https://deno.land/std@0.204.0/io/read_lines.ts" | ||
import { writeAll } from "https://deno.land/std@0.204.0/streams/write_all.ts" | ||
import { parse as parseYaml } from "https://deno.land/std@0.204.0/yaml/parse.ts" | ||
import { SEP } from "https://deno.land/std@0.204.0/path/mod.ts" | ||
import { fromFileUrl } from "https://deno.land/std@0.204.0/path/from_file_url.ts" | ||
import * as crypto from "https://deno.land/std@0.196.0/crypto/mod.ts" | ||
import { moveSync } from "https://deno.land/std@0.196.0/fs/move.ts" | ||
import { readLines } from "https://deno.land/std@0.196.0/io/read_lines.ts" | ||
import { writeAll } from "https://deno.land/std@0.196.0/streams/write_all.ts" | ||
import { parse as parseYaml } from "https://deno.land/std@0.196.0/yaml/parse.ts" | ||
import { SEP } from "https://deno.land/std@0.196.0/path/mod.ts" | ||
import { fromFileUrl } from "https://deno.land/std@0.196.0/path/mod.ts" | ||
|
||
const streams = { writeAll } | ||
const io = { readLines } | ||
|
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 |
---|---|---|
|
@@ -85,3 +85,10 @@ Deno.test("validatePackageRequirement - number constraint", () => { | |
const result = validatePackageRequirement("pkgx.sh/test", 1) | ||
assertEquals(result?.constraint.toString(), "^1") | ||
}) | ||
|
||
Deno.test("find", async () => { | ||
useTestConfig() | ||
const foo = await usePantry().find("[email protected]") | ||
assertEquals(foo.length, 1) | ||
assertEquals(foo[0].project, "python.org") | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,53 @@ | ||
import specimen, { _internals } from "./useSync.ts" | ||
import { useTestConfig } from "./useTestConfig.ts" | ||
import * as mock from "deno/testing/mock.ts" | ||
import { assert } from "deno/assert/mod.ts" | ||
import usePantry from "./usePantry.ts" | ||
import useSync from "./useSync.ts" | ||
|
||
// NOTE actually syncs from github | ||
// TODO unit tests should not do actual network calls, instead make an implementation suite | ||
|
||
Deno.test("useSync", async runner => { | ||
await runner.step("w/o git", async () => { | ||
const conf = useTestConfig({}) | ||
usePantry().prefix.rm({ recursive: true }) // we need to delete the fixtured pantry | ||
assert(conf.git === undefined) | ||
await test() | ||
}) | ||
|
||
await runner.step({ | ||
name: "w/git", | ||
ignore: Deno.build.os == 'windows' && !Deno.env.get("CI"), | ||
async fn() { | ||
const conf = useTestConfig({ PATH: "/usr/bin" }) | ||
const stub = mock.stub(_internals, "cache", async () => {}) | ||
|
||
try { | ||
await runner.step("w/o git", async () => { | ||
const conf = useTestConfig({}) | ||
usePantry().prefix.rm({ recursive: true }) // we need to delete the fixtured pantry | ||
assert(conf.git !== undefined) | ||
assert(conf.git === undefined) | ||
await test() | ||
}) | ||
|
||
// test the “already cloned” code-path | ||
await useSync() | ||
} | ||
}) | ||
|
||
async function test() { | ||
let errord = false | ||
try { | ||
await usePantry().project("gnu.org/gcc").available() | ||
} catch { | ||
errord = true | ||
} | ||
assert(errord, `should be no pantry but there is! ${usePantry().prefix}`) | ||
await runner.step({ | ||
name: "w/git", | ||
ignore: Deno.build.os == 'windows' && !Deno.env.get("CI"), | ||
async fn() { | ||
const conf = useTestConfig({ PATH: "/usr/bin" }) | ||
usePantry().prefix.rm({ recursive: true }) // we need to delete the fixtured pantry | ||
assert(conf.git !== undefined) | ||
await test() | ||
|
||
// test the “already cloned” code-path | ||
await specimen() | ||
} | ||
}) | ||
|
||
await useSync() | ||
async function test() { | ||
let errord = false | ||
try { | ||
await usePantry().project("gnu.org/gcc").available() | ||
} catch { | ||
errord = true | ||
} | ||
assert(errord, `should be no pantry but there is! ${usePantry().prefix}`) | ||
|
||
assert(await usePantry().project("gnu.org/gcc").available()) | ||
await specimen() | ||
|
||
assert(await usePantry().project("gnu.org/gcc").available()) | ||
} | ||
|
||
} finally { | ||
stub.restore() | ||
} | ||
|
||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// the sqlite lib we use only works in deno | ||
|
||
import { PackageRequirement } from "../../mod.ts"; | ||
|
||
export default async function() | ||
{} | ||
|
||
export function provides(_program: string): string[] { | ||
throw new Error() | ||
} | ||
|
||
export function dependencies(_project: string): PackageRequirement[] { | ||
throw new Error() | ||
} | ||
|
||
export function completion(_prefix: string): string[] { | ||
throw new Error() | ||
} | ||
|
||
/// is the cache available? | ||
export function available(): boolean { | ||
return false | ||
} | ||
|
||
export function companions(_project: string): PackageRequirement[] { | ||
throw new Error() | ||
} | ||
|
||
export function runtime_env(_project: string): Record<string, string> { | ||
throw new Error() | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import specimen, { provides, dependencies, available, runtime_env, completion, companions } from "./useSyncCache.ts" | ||
import { useTestConfig } from "./useTestConfig.ts" | ||
import { assert, assertEquals } from "deno/assert/mod.ts" | ||
import { _internals } from "./useSync.ts" | ||
import usePantry from "./usePantry.ts" | ||
|
||
// NOTE actually syncs from github | ||
// TODO unit tests should not do actual network calls, instead make an implementation suite | ||
|
||
Deno.test({ | ||
name: "useSyncCache", | ||
ignore: Deno.build.os == 'windows', | ||
async fn() { | ||
useTestConfig() | ||
await _internals.sync(usePantry().prefix.parent()) | ||
await specimen() | ||
|
||
//TODO test better | ||
assert(available()) | ||
assertEquals((await provides('node'))?.[0], 'nodejs.org') | ||
// assertEquals((await dependencies('nodejs.org'))?.length, 3) | ||
assert(new Set(await completion('nod')).has("node")) | ||
assertEquals((await companions("nodejs.org"))?.[0]?.project, "npmjs.com") | ||
assert((await runtime_env("numpy.org"))?.["PYTHONPATH"]) | ||
} | ||
}) |
Oops, something went wrong.