Skip to content

Commit

Permalink
test: link tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 17, 2023
1 parent 4bbf966 commit 37743d4
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
test: ['test:integration:install', 'test:integration:link']
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
Expand All @@ -40,7 +41,7 @@ jobs:
- uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main
- run: yarn build
- name: Run tests
run: yarn test:integration:install
run: yarn ${{matrix.test}}

unit-tests:
uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"test:integration": "mocha \"test/**/*.integration.ts\"",
"test:integration:sf": "mocha \"test/**/sf.integration.ts\"",
"test:integration:install": "mocha \"test/**/install.integration.ts\"",
"test:integration:link": "mocha \"test/**/link.integration.ts\"",
"version": "oclif readme && git add README.md"
},
"type": "module",
Expand Down
82 changes: 82 additions & 0 deletions test/integration/link.integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {ux} from '@oclif/core'
import {expect} from 'chai'
import {exec as cpExec} from 'node:child_process'
import {rm} from 'node:fs/promises'
import {tmpdir} from 'node:os'
import {join} from 'node:path'
import {SinonSandbox, createSandbox} from 'sinon'

import PluginsIndex from '../../src/commands/plugins/index.js'
import PluginsLink from '../../src/commands/plugins/link.js'
import PluginsUninstall from '../../src/commands/plugins/uninstall.js'

async function exec(cmd: string, opts?: {cwd?: string}) {
return new Promise((resolve, reject) => {
cpExec(cmd, opts, (err, stdout, stderr) => {
if (err) return reject(err)
resolve({code: 0, stderr, stdout})
})
})
}

describe('link/unlink integration tests', () => {
let sandbox: SinonSandbox
let stubs: ReturnType<typeof ux.makeStubs>

const cacheDir = join(tmpdir(), 'plugin-plugins-tests', 'cache')
const configDir = join(tmpdir(), 'plugin-plugins-tests', 'config')
const dataDir = join(tmpdir(), 'plugin-plugins-tests', 'data')
const pluginDir = join(tmpdir(), 'plugin-plugins-tests', 'plugin')
const repo = 'https://github.com/oclif/plugin-test-esm-1.git'

before(async () => {
try {
await Promise.all([
rm(cacheDir, {force: true, recursive: true}),
rm(configDir, {force: true, recursive: true}),
rm(dataDir, {force: true, recursive: true}),
rm(pluginDir, {force: true, recursive: true}),
])
} catch {}

await exec(`git clone ${repo} ${pluginDir} --depth 1`)
await exec('yarn', {cwd: pluginDir})
await exec('yarn build', {cwd: pluginDir})
})

beforeEach(() => {
sandbox = createSandbox()
stubs = ux.makeStubs(sandbox)
process.env.MYCLI_CACHE_DIR = cacheDir
process.env.MYCLI_CONFIG_DIR = configDir
process.env.MYCLI_DATA_DIR = dataDir
})

afterEach(() => {
sandbox.restore()

delete process.env.MYCLI_CACHE_DIR
delete process.env.MYCLI_CONFIG_DIR
delete process.env.MYCLI_DATA_DIR
})

it('should return "No Plugins" if no plugins are linked', async () => {
await PluginsIndex.run([], process.cwd())
expect(stubs.stdout.firstCall.firstArg).to.equal('No plugins installed.\n')
})

it('should link plugin', async () => {
await PluginsLink.run([pluginDir, '--no-install'], process.cwd())

const result = await PluginsIndex.run([], process.cwd())
expect(stubs.stdout.firstCall.firstArg).to.include('test-esm-1')
expect(result.some((r) => r.name === '@oclif/plugin-test-esm-1')).to.be.true
})

it('should unlink plugin', async () => {
await PluginsUninstall.run([pluginDir], process.cwd())

await PluginsIndex.run([], process.cwd())
expect(stubs.stdout.firstCall.firstArg).to.equal('No plugins installed.\n')
})
})

0 comments on commit 37743d4

Please sign in to comment.