|
| 1 | +import {ppath, xfs} from '@yarnpkg/fslib'; |
| 2 | +import {fs as fsUtils} from 'pkg-tests-core'; |
| 3 | +import {tests} from 'pkg-tests-core'; |
| 4 | + |
| 5 | +describe(`Protocols`, () => { |
| 6 | + describe(`jsr:`, () => { |
| 7 | + test( |
| 8 | + `it should allow installing a package from a jsr registry`, |
| 9 | + makeTemporaryEnv( |
| 10 | + { |
| 11 | + dependencies: {[`no-deps-jsr`]: `jsr:1.0.0`}, |
| 12 | + }, |
| 13 | + async ({path, run, source}) => { |
| 14 | + await xfs.writeFilePromise(ppath.join(path, `.yarnrc.yml`), JSON.stringify({ |
| 15 | + [`npmScopes`]: { |
| 16 | + [`jsr`]: { |
| 17 | + [`npmRegistryServer`]: `${await tests.startPackageServer()}/registry/jsr`, |
| 18 | + }, |
| 19 | + }, |
| 20 | + })); |
| 21 | + |
| 22 | + await run(`install`); |
| 23 | + |
| 24 | + await expect(source(`require('no-deps-jsr')`)).resolves.toMatchObject({ |
| 25 | + // The package name is prefixed with @jsr/ because that's what the registry returns |
| 26 | + name: `@jsr/no-deps-jsr`, |
| 27 | + version: `1.0.0`, |
| 28 | + }); |
| 29 | + }, |
| 30 | + ), |
| 31 | + ); |
| 32 | + |
| 33 | + test( |
| 34 | + `it should allow renaming packages`, |
| 35 | + makeTemporaryEnv( |
| 36 | + { |
| 37 | + dependencies: {[`foo`]: `jsr:[email protected]`}, |
| 38 | + }, |
| 39 | + async ({path, run, source}) => { |
| 40 | + await xfs.writeFilePromise(ppath.join(path, `.yarnrc.yml`), JSON.stringify({ |
| 41 | + [`npmScopes`]: { |
| 42 | + [`jsr`]: { |
| 43 | + [`npmRegistryServer`]: `${await tests.startPackageServer()}/registry/jsr`, |
| 44 | + }, |
| 45 | + }, |
| 46 | + })); |
| 47 | + |
| 48 | + await run(`install`); |
| 49 | + |
| 50 | + await expect(source(`require('foo')`)).resolves.toMatchObject({ |
| 51 | + name: `@jsr/no-deps-jsr`, |
| 52 | + version: `1.0.0`, |
| 53 | + }); |
| 54 | + }, |
| 55 | + ), |
| 56 | + ); |
| 57 | + |
| 58 | + test( |
| 59 | + `it should replace the jsr registry with a npm registry during packing`, |
| 60 | + makeTemporaryEnv( |
| 61 | + { |
| 62 | + dependencies: {[`no-deps-jsr`]: `jsr:1.0.0`}, |
| 63 | + }, |
| 64 | + async ({path, run, source}) => { |
| 65 | + await xfs.writeFilePromise(ppath.join(path, `.yarnrc.yml`), JSON.stringify({ |
| 66 | + [`npmScopes`]: { |
| 67 | + [`jsr`]: { |
| 68 | + [`npmRegistryServer`]: `${await tests.startPackageServer()}/registry/jsr`, |
| 69 | + }, |
| 70 | + }, |
| 71 | + })); |
| 72 | + |
| 73 | + await run(`install`); |
| 74 | + await run(`pack`); |
| 75 | + |
| 76 | + const tarballPath = ppath.join(path, `package.tgz`); |
| 77 | + const unpackedPath = ppath.join(path, `unpacked`); |
| 78 | + |
| 79 | + await xfs.mkdirPromise(unpackedPath); |
| 80 | + await fsUtils.unpackToDirectory(unpackedPath, tarballPath); |
| 81 | + |
| 82 | + const manifest = await xfs.readJsonPromise(ppath.join(unpackedPath, `package`, `package.json`)); |
| 83 | + |
| 84 | + expect(manifest).toMatchObject({ |
| 85 | + dependencies: { |
| 86 | + [`no-deps-jsr`]: `npm:@jsr/[email protected]`, |
| 87 | + }, |
| 88 | + }); |
| 89 | + }, |
| 90 | + ), |
| 91 | + ); |
| 92 | + }); |
| 93 | +}); |
0 commit comments