|
1 | 1 | 'use strict'
|
2 | 2 |
|
| 3 | +const path = require('path') |
| 4 | +const proxyquire = require('proxyquire') |
3 | 5 | const createInstantiatePlugin = require('../../lib/plugin').createInstantiatePlugin
|
4 | 6 |
|
5 | 7 | describe('plugin', () => {
|
@@ -58,4 +60,51 @@ describe('plugin', () => {
|
58 | 60 | expect(fakes.emitter.emit).to.have.been.calledWith('load_error', 'unknown', 'name')
|
59 | 61 | })
|
60 | 62 | })
|
| 63 | + |
| 64 | + describe('resolve', () => { |
| 65 | + // Base path should be the same as the one produced by the code under test. |
| 66 | + const base = path.resolve(__dirname, '..', '..', '..') |
| 67 | + const directories = { |
| 68 | + [base]: ['karma-fancy-plugin', 'other-package', 'karma-powerful-plugin', 'yet-another-package', '@scope'], |
| 69 | + [path.join(base, '@scope')]: ['karma-super-plugin', 'not-a-plugin'] |
| 70 | + } |
| 71 | + |
| 72 | + const { resolve } = proxyquire( |
| 73 | + '../../lib/plugin', |
| 74 | + { |
| 75 | + 'graceful-fs': { readdirSync: (dir) => directories[dir] }, |
| 76 | + 'karma-fancy-plugin': { name: 'karma-fancy-plugin', '@noCallThru': true }, |
| 77 | + 'karma-powerful-plugin': { name: 'karma-powerful-plugin', '@noCallThru': true }, |
| 78 | + '@scope/karma-super-plugin': { name: '@scope/karma-super-plugin', '@noCallThru': true }, |
| 79 | + // Plugins are require()'d using an absolute path if they were resolved from the glob. |
| 80 | + [path.join(base, 'karma-fancy-plugin')]: { name: 'karma-fancy-plugin', '@noCallThru': true }, |
| 81 | + [path.join(base, 'karma-powerful-plugin')]: { name: 'karma-powerful-plugin', '@noCallThru': true }, |
| 82 | + [path.join(base, '@scope/karma-super-plugin')]: { name: '@scope/karma-super-plugin', '@noCallThru': true } |
| 83 | + } |
| 84 | + ) |
| 85 | + |
| 86 | + it('loads simple plugin', () => { |
| 87 | + const modules = resolve(['karma-powerful-plugin'], null) |
| 88 | + |
| 89 | + expect(modules.map((m) => m.name)).to.deep.equal(['karma-powerful-plugin']) |
| 90 | + }) |
| 91 | + |
| 92 | + it('loads scoped plugin', () => { |
| 93 | + const modules = resolve(['@scope/karma-super-plugin'], null) |
| 94 | + |
| 95 | + expect(modules.map((m) => m.name)).to.deep.equal(['@scope/karma-super-plugin']) |
| 96 | + }) |
| 97 | + |
| 98 | + it('loads simple plugins with globs', () => { |
| 99 | + const modules = resolve(['karma-*'], null) |
| 100 | + |
| 101 | + expect(modules.map((m) => m.name)).to.deep.equal(['karma-fancy-plugin', 'karma-powerful-plugin']) |
| 102 | + }) |
| 103 | + |
| 104 | + it('loads scoped plugins with globs', () => { |
| 105 | + const modules = resolve(['@*/karma-*'], null) |
| 106 | + |
| 107 | + expect(modules.map((m) => m.name)).to.deep.equal(['@scope/karma-super-plugin']) |
| 108 | + }) |
| 109 | + }) |
61 | 110 | })
|
0 commit comments