Skip to content

Commit

Permalink
test(plugins): add missing tests for plugin resolution logic (#3661)
Browse files Browse the repository at this point in the history
  • Loading branch information
devoto13 committed Mar 11, 2021
1 parent a2bca0d commit d3ff91a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/unit/plugin.spec.js
@@ -1,5 +1,7 @@
'use strict'

const path = require('path')
const proxyquire = require('proxyquire')
const createInstantiatePlugin = require('../../lib/plugin').createInstantiatePlugin

describe('plugin', () => {
Expand Down Expand Up @@ -58,4 +60,51 @@ describe('plugin', () => {
expect(fakes.emitter.emit).to.have.been.calledWith('load_error', 'unknown', 'name')
})
})

describe('resolve', () => {
// Base path should be the same as the one produced by the code under test.
const base = path.resolve(__dirname, '..', '..', '..')
const directories = {
[base]: ['karma-fancy-plugin', 'other-package', 'karma-powerful-plugin', 'yet-another-package', '@scope'],
[path.join(base, '@scope')]: ['karma-super-plugin', 'not-a-plugin']
}

const { resolve } = proxyquire(
'../../lib/plugin',
{
'graceful-fs': { readdirSync: (dir) => directories[dir] },
'karma-fancy-plugin': { name: 'karma-fancy-plugin', '@noCallThru': true },
'karma-powerful-plugin': { name: 'karma-powerful-plugin', '@noCallThru': true },
'@scope/karma-super-plugin': { name: '@scope/karma-super-plugin', '@noCallThru': true },
// Plugins are require()'d using an absolute path if they were resolved from the glob.
[path.join(base, 'karma-fancy-plugin')]: { name: 'karma-fancy-plugin', '@noCallThru': true },
[path.join(base, 'karma-powerful-plugin')]: { name: 'karma-powerful-plugin', '@noCallThru': true },
[path.join(base, '@scope/karma-super-plugin')]: { name: '@scope/karma-super-plugin', '@noCallThru': true }
}
)

it('loads simple plugin', () => {
const modules = resolve(['karma-powerful-plugin'], null)

expect(modules.map((m) => m.name)).to.deep.equal(['karma-powerful-plugin'])
})

it('loads scoped plugin', () => {
const modules = resolve(['@scope/karma-super-plugin'], null)

expect(modules.map((m) => m.name)).to.deep.equal(['@scope/karma-super-plugin'])
})

it('loads simple plugins with globs', () => {
const modules = resolve(['karma-*'], null)

expect(modules.map((m) => m.name)).to.deep.equal(['karma-fancy-plugin', 'karma-powerful-plugin'])
})

it('loads scoped plugins with globs', () => {
const modules = resolve(['@*/karma-*'], null)

expect(modules.map((m) => m.name)).to.deep.equal(['@scope/karma-super-plugin'])
})
})
})

0 comments on commit d3ff91a

Please sign in to comment.