%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
const t = require('tap') const { load: loadMockNpm } = require('../../fixtures/mock-npm') t.cleanSnapshot = (str) => { const normalizePath = p => p .replace(/\\+/g, '/') .replace(/\r\n/g, '\n') return normalizePath(str) .replace(new RegExp(normalizePath(process.cwd()), 'g'), '{CWD}') // normalize between windows and posix .replace(new RegExp('lib/node_modules', 'g'), 'node_modules') } t.test('simple query', async t => { const { npm, joinedOutput } = await loadMockNpm(t, { prefixDir: { node_modules: { a: { name: 'a', version: '1.0.0', }, b: { name: 'b', version: '^2.0.0', }, }, 'package.json': JSON.stringify({ name: 'project', dependencies: { a: '^1.0.0', b: '^1.0.0', }, peerDependencies: { c: '1.0.0', }, }), }, }) await npm.exec('query', [':root, :root > *']) t.matchSnapshot(joinedOutput(), 'should return root object and direct children') }) t.test('recursive tree', async t => { const { npm, joinedOutput } = await loadMockNpm(t, { prefixDir: { node_modules: { a: { name: 'a', version: '1.0.0', }, b: { name: 'b', version: '^2.0.0', dependencies: { a: '1.0.0', }, }, }, 'package.json': JSON.stringify({ name: 'project', dependencies: { a: '^1.0.0', b: '^1.0.0', }, }), }, }) await npm.exec('query', ['*']) t.matchSnapshot(joinedOutput(), 'should return everything in the tree, accounting for recursion') }) t.test('workspace query', async t => { const { npm, joinedOutput } = await loadMockNpm(t, { config: { workspaces: ['c'], }, prefixDir: { node_modules: { a: { name: 'a', version: '1.0.0', }, b: { name: 'b', version: '^2.0.0', }, c: t.fixture('symlink', '../c'), }, c: { 'package.json': JSON.stringify({ name: 'c', version: '1.0.0', }), }, 'package.json': JSON.stringify({ name: 'project', workspaces: ['c'], dependencies: { a: '^1.0.0', b: '^1.0.0', }, }), }, }) await npm.exec('query', [':scope'], ['c']) t.matchSnapshot(joinedOutput(), 'should return workspace object') }) t.test('include-workspace-root', async t => { const { npm, joinedOutput } = await loadMockNpm(t, { config: { 'include-workspace-root': true, workspaces: ['c'], }, prefixDir: { node_modules: { a: { name: 'a', version: '1.0.0', }, b: { name: 'b', version: '^2.0.0', }, c: t.fixture('symlink', '../c'), }, c: { 'package.json': JSON.stringify({ name: 'c', version: '1.0.0', }), }, 'package.json': JSON.stringify({ name: 'project', workspaces: ['c'], dependencies: { a: '^1.0.0', b: '^1.0.0', }, }), }, }) await npm.exec('query', [':scope'], ['c']) t.matchSnapshot(joinedOutput(), 'should return workspace object and root object') }) t.test('linked node', async t => { const { npm, joinedOutput } = await loadMockNpm(t, { prefixDir: { node_modules: { a: t.fixture('symlink', '../a'), }, a: { 'package.json': JSON.stringify({ name: 'a', version: '1.0.0', }), }, 'package.json': JSON.stringify({ name: 'project', dependencies: { a: 'file:./a', }, }), }, }) await npm.exec('query', ['[name=a]']) t.matchSnapshot(joinedOutput(), 'should return linked node res') }) t.test('global', async t => { const { npm, joinedOutput } = await loadMockNpm(t, { config: { global: true, }, // This is a global dir that works in both windows and non-windows, that's // why it has two node_modules folders globalPrefixDir: { node_modules: { lorem: { 'package.json': JSON.stringify({ name: 'lorem', version: '2.0.0', }), }, }, lib: { node_modules: { lorem: { 'package.json': JSON.stringify({ name: 'lorem', version: '2.0.0', }), }, }, }, }, }) await npm.exec('query', ['[name=lorem]']) t.matchSnapshot(joinedOutput(), 'should return global package') })