Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger committed Apr 23, 2023
1 parent 2c5c0bb commit d9e6f0b
Showing 1 changed file with 155 additions and 0 deletions.
155 changes: 155 additions & 0 deletions packages/core/test/actions/install-packages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ it('installs the given php package as development dependencies', async() => awai

it('installs the given node package with npm by default', async() => await usingSandbox({
fn: async({ targetDirectory }, makeTestPreset) => {
process.env.npm_config_user_agent = undefined
const { executePreset } = await makeTestPreset({
handler: async() => await installPackages({
for: 'node',
Expand All @@ -87,6 +88,91 @@ it('installs the given node package with npm by default', async() => await using
targetStructure: { 'package.json': { type: 'file', content: '{}' } },
}))

it('installs the given node package with npm when npm was used to run the preset', async() => await usingSandbox({
fn: async({ targetDirectory }, makeTestPreset) => {
process.env.npm_config_user_agent = 'npm'
const { executePreset } = await makeTestPreset({
handler: async() => await installPackages({
for: 'node',
packages: 'debug@4.3.3',
}),
})

await executePreset()
await expectStructureMatches(targetDirectory, {
'node_modules': { type: 'directory' },
'node_modules/debug': { type: 'directory' },
'package-lock.json': { type: 'file' },
'package.json': {
type: 'file',
json: {
dependencies: {
debug: '^4.3.3',
},
},
},
})
},
targetStructure: { 'package.json': { type: 'file', content: '{}' } },
}))

it('installs the given node package with yarn when yarn was used to run the preset', async() => await usingSandbox({
fn: async({ targetDirectory }, makeTestPreset) => {
process.env.npm_config_user_agent = 'yarn'
const { executePreset } = await makeTestPreset({
handler: async() => await installPackages({
for: 'node',
packages: 'debug@^4.3.4',
}),
})

await executePreset()
await expectStructureMatches(targetDirectory, {
'node_modules': { type: 'directory' },
'node_modules/debug': { type: 'directory' },
'yarn.lock': { type: 'file' },
'package.json': {
type: 'file',
json: {
dependencies: {
debug: '^4.3.4',
},
},
},
})
},
targetStructure: { 'package.json': { type: 'file', content: '{}' } },
}))

it('installs the given node package with pnpm when pnpm was used to run the preset', async() => await usingSandbox({
fn: async({ targetDirectory }, makeTestPreset) => {
process.env.npm_config_user_agent = 'pnpm'
const { executePreset } = await makeTestPreset({
handler: async() => await installPackages({
for: 'node',
packages: 'debug@^4.3.4',
additionalArgs: ['--ignore-workspace'],
}),
})

await executePreset()
await expectStructureMatches(targetDirectory, {
'node_modules': { type: 'directory' },
'node_modules/debug': { type: 'directory' },
'pnpm-lock.yaml': { type: 'file' },
'package.json': {
type: 'file',
json: {
dependencies: {
debug: '^4.3.4',
},
},
},
})
},
targetStructure: { 'package.json': { type: 'file', content: '{}' } },
}))

it('installs the given node package as development dependencies', async() => await usingSandbox({
fn: async({ targetDirectory }, makeTestPreset) => {
const { executePreset } = await makeTestPreset({
Expand Down Expand Up @@ -123,6 +209,7 @@ it('installs the given node package with the specified package manager', async()
for: 'node',
packages: 'debug@4.3.3',
packageManager: 'pnpm',
additionalArgs: ['--ignore-workspace'],
}),
})

Expand Down Expand Up @@ -175,6 +262,7 @@ it('installs the given packages at once', async() => await usingSandbox({

it('installs packages already present in package.json with npm', async() => await usingSandbox({
fn: async({ targetDirectory }, makeTestPreset) => {
process.env.npm_config_user_agent = undefined
const { executePreset } = await makeTestPreset({
handler: async() => await installPackages(),
})
Expand Down Expand Up @@ -279,3 +367,70 @@ it('installs existing packages with yarn', async() => await usingSandbox({
'package.json': { type: 'file', content: '{"dependencies": {"debug": "^4.3.4"}}' },
},
}))

it('installs existing packages with npm when npm was used to run the preset', async() => await usingSandbox({
fn: async({ targetDirectory }, makeTestPreset) => {
process.env.npm_config_user_agent = 'npm'
const { executePreset } = await makeTestPreset({
handler: async() => await installPackages({
for: 'node',
}),
})

await executePreset()
await expectStructureMatches(targetDirectory, {
'node_modules': { type: 'directory' },
'node_modules/debug': { type: 'directory' },
'package-lock.json': { type: 'file' },
})
},
targetStructure: {
...emptyPackageJsonStructure,
'package.json': { type: 'file', content: '{"dependencies": {"debug": "^4.3.4"}}' },
},
}))

it('installs existing packages with yarn when yarn was used to run the preset', async() => await usingSandbox({
fn: async({ targetDirectory }, makeTestPreset) => {
process.env.npm_config_user_agent = 'yarn'
const { executePreset } = await makeTestPreset({
handler: async() => await installPackages({
for: 'node',
}),
})

await executePreset()
await expectStructureMatches(targetDirectory, {
'node_modules': { type: 'directory' },
'node_modules/debug': { type: 'directory' },
'yarn.lock': { type: 'file' },
})
},
targetStructure: {
...emptyPackageJsonStructure,
'package.json': { type: 'file', content: '{"dependencies": {"debug": "^4.3.4"}}' },
},
}))

it('installs existing packages with pnpm when pnpm was used to run the preset', async() => await usingSandbox({
fn: async({ targetDirectory }, makeTestPreset) => {
process.env.npm_config_user_agent = 'pnpm'
const { executePreset } = await makeTestPreset({
handler: async() => await installPackages({
for: 'node',
additionalArgs: ['--ignore-workspace'],
}),
})

await executePreset()
await expectStructureMatches(targetDirectory, {
'node_modules': { type: 'directory' },
'node_modules/debug': { type: 'directory' },
'pnpm-lock.yaml': { type: 'file' },
})
},
targetStructure: {
...emptyPackageJsonStructure,
'package.json': { type: 'file', content: '{"dependencies": {"debug": "^4.3.4"}}' },
},
}))

0 comments on commit d9e6f0b

Please sign in to comment.