diff --git a/@commitlint/cli/package.json b/@commitlint/cli/package.json index 66b66cf8b2..9ea3798c4a 100644 --- a/@commitlint/cli/package.json +++ b/@commitlint/cli/package.json @@ -50,7 +50,6 @@ "@commitlint/test": "8.2.0", "@commitlint/utils": "^8.3.4", "babel-preset-commitlint": "^8.2.0", - "concurrently": "3.6.1", "cross-env": "6.0.3", "execa": "0.11.0", "mkdirp": "0.5.1", diff --git a/@commitlint/lint/package.json b/@commitlint/lint/package.json index 6868e42474..adb06a0f3f 100644 --- a/@commitlint/lint/package.json +++ b/@commitlint/lint/package.json @@ -72,8 +72,7 @@ "concurrently": "3.6.1", "cross-env": "6.0.3", "execa": "0.11.0", - "globby": "10.0.1", - "proxyquire": "2.1.3" + "globby": "10.0.1" }, "dependencies": { "@commitlint/is-ignored": "^8.3.5", diff --git a/@commitlint/load/package.json b/@commitlint/load/package.json index 0d8cbddadf..48ff4699bf 100644 --- a/@commitlint/load/package.json +++ b/@commitlint/load/package.json @@ -7,33 +7,12 @@ "lib/" ], "scripts": { - "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", + "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", "deps": "dep-check", "pkg": "pkg-check --skip-import", - "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", - "test": "ava -c 4 --verbose && ava src/index.serial-test.js --verbose", + "start": "yarn run watch", "watch": "babel src --out-dir lib --watch --source-maps" }, - "ava": { - "files": [ - "src/**/*.test.js", - "!lib/**/*" - ], - "source": [ - "src/**/*.js", - "!lib/**/*" - ], - "babel": { - "testOptions": { - "presets": [ - "babel-preset-commitlint" - ] - } - }, - "require": [ - "@babel/register" - ] - }, "babel": { "presets": [ "babel-preset-commitlint" @@ -67,9 +46,7 @@ "@babel/register": "7.7.7", "@commitlint/test": "8.2.0", "@commitlint/utils": "^8.3.4", - "ava": "2.4.0", "babel-preset-commitlint": "^8.2.0", - "concurrently": "3.6.1", "cross-env": "6.0.3", "execa": "0.11.0", "globby": "10.0.1" diff --git a/@commitlint/load/src/index.serial-test.js b/@commitlint/load/src/index.serial-test.js deleted file mode 100644 index 43f499ca66..0000000000 --- a/@commitlint/load/src/index.serial-test.js +++ /dev/null @@ -1,19 +0,0 @@ -import {fix} from '@commitlint/test'; -import test from 'ava'; - -import load from '.'; - -test.serial('default cwd option to process.cwd()', async t => { - const cwd = await fix.bootstrap('fixtures/basic'); - const before = process.cwd(); - process.chdir(cwd); - - try { - const actual = await load(); - t.true(actual.rules.basic); - } catch (err) { - throw err; - } finally { - process.chdir(before); - } -}); diff --git a/@commitlint/load/src/index.test.js b/@commitlint/load/src/index.test.js index 5407d33edf..b96c4318eb 100644 --- a/@commitlint/load/src/index.test.js +++ b/@commitlint/load/src/index.test.js @@ -1,111 +1,134 @@ import path from 'path'; import {fix, git, npm} from '@commitlint/test'; -import test from 'ava'; import execa from 'execa'; import resolveFrom from 'resolve-from'; import load from '.'; -const proxyquire = require('proxyquire') - .noCallThru() - .noPreserveCache(); +const baseCwd = process.cwd(); -test('extends-empty should have no rules', async t => { - const cwd = await git.bootstrap('fixtures/extends-empty'); +const fixBootstrap = fixture => fix.bootstrap(fixture, __dirname); +const gitBootstrap = fixture => git.bootstrap(fixture, __dirname); +const npmBootstrap = fixture => npm.bootstrap(fixture, __dirname); + +afterEach(() => { + process.chdir(baseCwd); + + jest.restoreAllMocks(); +}); + +test('default cwd option to process.cwd()', async () => { + const cwd = await fixBootstrap('fixtures/basic'); + process.chdir(cwd); + + const actual = await load(); + expect(actual.rules.basic).toBe(true); +}); + +test('extends-empty should have no rules', async () => { + const cwd = await gitBootstrap('fixtures/extends-empty'); const actual = await load({}, {cwd}); - t.deepEqual(actual.rules, {}); + expect(actual.rules).toEqual({}); }); -test('uses seed as configured', async t => { - const cwd = await git.bootstrap('fixtures/extends-empty'); +test('uses seed as configured', async () => { + const cwd = await gitBootstrap('fixtures/extends-empty'); const actual = await load({rules: {foo: 'bar'}}, {cwd}); - t.is(actual.rules.foo, 'bar'); + expect(actual.rules.foo).toBe('bar'); }); -test('rules should be loaded from relative config file', async t => { +test('rules should be loaded from relative config file', async () => { const file = 'config/commitlint.config.js'; - const cwd = await git.bootstrap('fixtures/specify-config-file'); + const cwd = await gitBootstrap('fixtures/specify-config-file'); const actual = await load({}, {cwd, file}); - t.is(actual.rules.foo, 'bar'); + expect(actual.rules.foo).toBe('bar'); }); -test('rules should be loaded from absolute config file', async t => { - const cwd = await git.bootstrap('fixtures/specify-config-file'); +test('rules should be loaded from absolute config file', async () => { + const cwd = await gitBootstrap('fixtures/specify-config-file'); const file = path.join(cwd, 'config/commitlint.config.js'); const actual = await load({}, {cwd: process.cwd(), file}); - t.is(actual.rules.foo, 'bar'); + expect(actual.rules.foo).toBe('bar'); }); -test('plugins should be loaded from seed', async t => { - const plugin = {'@global': true}; - const scopedPlugin = {'@global': true}; - const stubbedLoad = proxyquire('.', { - 'commitlint-plugin-example': plugin, - '@scope/commitlint-plugin-example': scopedPlugin - }).default; - - const cwd = await git.bootstrap('fixtures/extends-empty'); - const actual = await stubbedLoad( - {plugins: ['example', '@scope/example']}, - {cwd} +test('plugins should be loaded from seed', async () => { + const mock1 = jest.mock( + 'commitlint-plugin-example', + () => ({'@global': true}), + { + virtual: true + } ); - t.deepEqual(actual.plugins, { - example: plugin, - '@scope/example': scopedPlugin + const mock2 = jest.mock( + '@scope/commitlint-plugin-example', + () => ({'@global': true}), + { + virtual: true + } + ); + + const cwd = await gitBootstrap('fixtures/extends-empty'); + const actual = await load({plugins: ['example', '@scope/example']}, {cwd}); + + expect(actual.plugins).toEqual({ + example: {'@global': true}, + '@scope/example': {'@global': true} }); }); -test('plugins should be loaded from config', async t => { - const plugin = {'@global': true}; - const scopedPlugin = {'@global': true}; - const stubbedLoad = proxyquire('.', { - 'commitlint-plugin-example': plugin, - '@scope/commitlint-plugin-example': scopedPlugin - }).default; +test('plugins should be loaded from config', async () => { + jest.mock('commitlint-plugin-example', () => ({'@global': true}), { + virtual: true + }); + jest.mock('@scope/commitlint-plugin-example', () => ({'@global': true}), { + virtual: true + }); - const cwd = await git.bootstrap('fixtures/extends-plugins'); - const actual = await stubbedLoad({}, {cwd}); - t.deepEqual(actual.plugins, { - example: plugin, - '@scope/example': scopedPlugin + const cwd = await gitBootstrap('fixtures/extends-plugins'); + const actual = await load({}, {cwd}); + expect(actual.plugins).toEqual({ + example: {'@global': true}, + '@scope/example': {'@global': true} }); }); -test('uses seed with parserPreset', async t => { - const cwd = await git.bootstrap('fixtures/parser-preset'); +test('uses seed with parserPreset', async () => { + const cwd = await gitBootstrap('fixtures/parser-preset'); const {parserPreset: actual} = await load( { parserPreset: './conventional-changelog-custom' }, {cwd} ); - t.is(actual.name, './conventional-changelog-custom'); - t.deepEqual(actual.parserOpts, { + expect(actual.name).toBe('./conventional-changelog-custom'); + expect(actual.parserOpts).toEqual({ headerPattern: /^(\w*)(?:\((.*)\))?-(.*)$/ }); }); -test('invalid extend should throw', async t => { - const cwd = await git.bootstrap('fixtures/extends-invalid'); - await t.throwsAsync(load({}, {cwd})); +test('invalid extend should throw', async () => { + const cwd = await gitBootstrap('fixtures/extends-invalid'); + await expect(load({}, {cwd})).rejects.toThrow( + 'Cannot find module "conventional-changelog-lint-config-____foooooo"' + ); }); -test('empty file should have no rules', async t => { - const cwd = await git.bootstrap('fixtures/empty-object-file'); +test('empty file should have no rules', async () => { + const cwd = await gitBootstrap('fixtures/empty-object-file'); const actual = await load({}, {cwd}); - t.deepEqual(actual.rules, {}); + expect(actual.rules).toEqual({}); }); -test('empty file should extend nothing', async t => { - const cwd = await git.bootstrap('fixtures/empty-file'); +test('empty file should extend nothing', async () => { + const cwd = await gitBootstrap('fixtures/empty-file'); const actual = await load({}, {cwd}); - t.deepEqual(actual.extends, []); + expect(actual.extends).toEqual([]); }); -test('respects cwd option', async t => { - const cwd = await git.bootstrap('fixtures/recursive-extends/first-extended'); +test('respects cwd option', async () => { + const cwd = await gitBootstrap('fixtures/recursive-extends/first-extended'); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: '@commitlint/format', extends: ['./second-extended'], plugins: {}, @@ -116,10 +139,10 @@ test('respects cwd option', async t => { }); }); -test('recursive extends', async t => { - const cwd = await git.bootstrap('fixtures/recursive-extends'); +test('recursive extends', async () => { + const cwd = await gitBootstrap('fixtures/recursive-extends'); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: '@commitlint/format', extends: ['./first-extended'], plugins: {}, @@ -131,11 +154,11 @@ test('recursive extends', async t => { }); }); -test('recursive extends with json file', async t => { - const cwd = await git.bootstrap('fixtures/recursive-extends-json'); +test('recursive extends with json file', async () => { + const cwd = await gitBootstrap('fixtures/recursive-extends-json'); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: '@commitlint/format', extends: ['./first-extended'], plugins: {}, @@ -147,11 +170,11 @@ test('recursive extends with json file', async t => { }); }); -test('recursive extends with yaml file', async t => { - const cwd = await git.bootstrap('fixtures/recursive-extends-yaml'); +test('recursive extends with yaml file', async () => { + const cwd = await gitBootstrap('fixtures/recursive-extends-yaml'); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: '@commitlint/format', extends: ['./first-extended'], plugins: {}, @@ -163,11 +186,11 @@ test('recursive extends with yaml file', async t => { }); }); -test('recursive extends with js file', async t => { - const cwd = await git.bootstrap('fixtures/recursive-extends-js'); +test('recursive extends with js file', async () => { + const cwd = await gitBootstrap('fixtures/recursive-extends-js'); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: '@commitlint/format', extends: ['./first-extended'], plugins: {}, @@ -179,11 +202,11 @@ test('recursive extends with js file', async t => { }); }); -test('recursive extends with package.json file', async t => { - const cwd = await git.bootstrap('fixtures/recursive-extends-package'); +test('recursive extends with package.json file', async () => { + const cwd = await gitBootstrap('fixtures/recursive-extends-package'); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: '@commitlint/format', extends: ['./first-extended'], plugins: {}, @@ -195,31 +218,30 @@ test('recursive extends with package.json file', async t => { }); }); -test('parser preset overwrites completely instead of merging', async t => { - const cwd = await git.bootstrap('fixtures/parser-preset-override'); +test('parser preset overwrites completely instead of merging', async () => { + const cwd = await gitBootstrap('fixtures/parser-preset-override'); const actual = await load({}, {cwd}); - t.is(actual.parserPreset.name, './custom'); - t.deepEqual(actual.parserPreset.parserOpts, { + expect(actual.parserPreset.name).toBe('./custom'); + expect(actual.parserPreset.parserOpts).toEqual({ headerPattern: /.*/ }); }); -test('recursive extends with parserPreset', async t => { - const cwd = await git.bootstrap('fixtures/recursive-parser-preset'); +test('recursive extends with parserPreset', async () => { + const cwd = await gitBootstrap('fixtures/recursive-parser-preset'); const actual = await load({}, {cwd}); - t.is(actual.parserPreset.name, './conventional-changelog-custom'); - t.is(typeof actual.parserPreset.parserOpts, 'object'); - t.deepEqual( - actual.parserPreset.parserOpts.headerPattern, + expect(actual.parserPreset.name).toBe('./conventional-changelog-custom'); + expect(typeof actual.parserPreset.parserOpts).toBe('object'); + expect(actual.parserPreset.parserOpts.headerPattern).toEqual( /^(\w*)(?:\((.*)\))?-(.*)$/ ); }); -test('ignores unknow keys', async t => { - const cwd = await git.bootstrap('fixtures/trash-file'); +test('ignores unknow keys', async () => { + const cwd = await gitBootstrap('fixtures/trash-file'); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: '@commitlint/format', extends: [], plugins: {}, @@ -230,11 +252,11 @@ test('ignores unknow keys', async t => { }); }); -test('ignores unknow keys recursively', async t => { - const cwd = await git.bootstrap('fixtures/trash-extend'); +test('ignores unknow keys recursively', async () => { + const cwd = await gitBootstrap('fixtures/trash-extend'); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: '@commitlint/format', extends: ['./one'], plugins: {}, @@ -245,14 +267,14 @@ test('ignores unknow keys recursively', async t => { }); }); -test('find up from given cwd', async t => { - const outer = await fix.bootstrap('fixtures/outer-scope'); +test('find up from given cwd', async () => { + const outer = await fixBootstrap('fixtures/outer-scope'); await git.init(path.join(outer, 'inner-scope')); const cwd = path.join(outer, 'inner-scope', 'child-scope'); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: '@commitlint/format', extends: [], plugins: {}, @@ -264,12 +286,12 @@ test('find up from given cwd', async t => { }); }); -test('find up config from outside current git repo', async t => { - const outer = await fix.bootstrap('fixtures/outer-scope'); +test('find up config from outside current git repo', async () => { + const outer = await fixBootstrap('fixtures/outer-scope'); const cwd = await git.init(path.join(outer, 'inner-scope')); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: '@commitlint/format', extends: [], plugins: {}, @@ -281,11 +303,11 @@ test('find up config from outside current git repo', async t => { }); }); -test('respects formatter option', async t => { - const cwd = await git.bootstrap('fixtures/formatter'); +test('respects formatter option', async () => { + const cwd = await gitBootstrap('fixtures/formatter'); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: 'commitlint-junit', extends: [], plugins: {}, @@ -293,11 +315,11 @@ test('respects formatter option', async t => { }); }); -test('resolves formatter relative from config directory', async t => { - const cwd = await git.bootstrap('fixtures/formatter-local-module'); +test('resolves formatter relative from config directory', async () => { + const cwd = await gitBootstrap('fixtures/formatter-local-module'); const actual = await load({}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: resolveFrom(cwd, './formatters/custom.js'), extends: [], plugins: {}, @@ -305,11 +327,11 @@ test('resolves formatter relative from config directory', async t => { }); }); -test('returns formatter name when unable to resolve from config directory', async t => { - const cwd = await git.bootstrap('fixtures/formatter-local-module'); +test('returns formatter name when unable to resolve from config directory', async () => { + const cwd = await gitBootstrap('fixtures/formatter-local-module'); const actual = await load({formatter: './doesnt/exists.js'}, {cwd}); - t.deepEqual(actual, { + expect(actual).toEqual({ formatter: './doesnt/exists.js', extends: [], plugins: {}, @@ -317,44 +339,44 @@ test('returns formatter name when unable to resolve from config directory', asyn }); }); -test('does not mutate config module reference', async t => { +test('does not mutate config module reference', async () => { const file = 'config/commitlint.config.js'; - const cwd = await git.bootstrap('fixtures/specify-config-file'); + const cwd = await gitBootstrap('fixtures/specify-config-file'); const configPath = path.join(cwd, file); const before = JSON.stringify(require(configPath)); await load({arbitraryField: true}, {cwd, file}); const after = JSON.stringify(require(configPath)); - t.is(before, after); + expect(before).toEqual(after); }); -test('resolves parser preset from conventional commits', async t => { - const cwd = await npm.bootstrap('fixtures/parser-preset-conventionalcommits'); +test('resolves parser preset from conventional commits', async () => { + const cwd = await npmBootstrap('fixtures/parser-preset-conventionalcommits'); const actual = await load({}, {cwd}); - t.is(actual.parserPreset.name, 'conventional-changelog-conventionalcommits'); - t.is(typeof actual.parserPreset.parserOpts, 'object'); - t.deepEqual( - actual.parserPreset.parserOpts.headerPattern, + expect(actual.parserPreset.name).toBe( + 'conventional-changelog-conventionalcommits' + ); + expect(typeof actual.parserPreset.parserOpts).toBe('object'); + expect(actual.parserPreset.parserOpts.headerPattern).toEqual( /^(\w*)(?:\((.*)\))?!?: (.*)$/ ); }); -test('resolves parser preset from conventional angular', async t => { - const cwd = await npm.bootstrap('fixtures/parser-preset-angular'); +test('resolves parser preset from conventional angular', async () => { + const cwd = await npmBootstrap('fixtures/parser-preset-angular'); const actual = await load({}, {cwd}); - t.is(actual.parserPreset.name, 'conventional-changelog-angular'); - t.is(typeof actual.parserPreset.parserOpts, 'object'); - t.deepEqual( - actual.parserPreset.parserOpts.headerPattern, + expect(actual.parserPreset.name).toBe('conventional-changelog-angular'); + expect(typeof actual.parserPreset.parserOpts).toBe('object'); + expect(actual.parserPreset.parserOpts.headerPattern).toEqual( /^(\w*)(?:\((.*)\))?: (.*)$/ ); }); -test('recursive resolves parser preset from conventional atom', async t => { - const cwd = await git.bootstrap( +test('recursive resolves parser preset from conventional atom', async () => { + const cwd = await gitBootstrap( 'fixtures/recursive-parser-preset-conventional-atom' ); // the package file is nested in 2 folders, `npm.bootstrap` cant do that @@ -364,21 +386,24 @@ test('recursive resolves parser preset from conventional atom', async t => { const actual = await load({}, {cwd}); - t.is(actual.parserPreset.name, 'conventional-changelog-atom'); - t.is(typeof actual.parserPreset.parserOpts, 'object'); - t.deepEqual(actual.parserPreset.parserOpts.headerPattern, /^(:.*?:) (.*)$/); + expect(actual.parserPreset.name).toBe('conventional-changelog-atom'); + expect(typeof actual.parserPreset.parserOpts).toBe('object'); + expect(actual.parserPreset.parserOpts.headerPattern).toEqual( + /^(:.*?:) (.*)$/ + ); }); -test('resolves parser preset from conventional commits without factory support', async t => { - const cwd = await npm.bootstrap( +test('resolves parser preset from conventional commits without factory support', async () => { + const cwd = await npmBootstrap( 'fixtures/parser-preset-conventional-without-factory' ); const actual = await load({}, {cwd}); - t.is(actual.parserPreset.name, 'conventional-changelog-conventionalcommits'); - t.is(typeof actual.parserPreset.parserOpts, 'object'); - t.deepEqual( - actual.parserPreset.parserOpts.headerPattern, + expect(actual.parserPreset.name).toBe( + 'conventional-changelog-conventionalcommits' + ); + expect(typeof actual.parserPreset.parserOpts).toBe('object'); + expect(actual.parserPreset.parserOpts.headerPattern).toEqual( /^(\w*)(?:\((.*)\))?!?: (.*)$/ ); }); diff --git a/@commitlint/load/src/utils/loadPlugin.test.js b/@commitlint/load/src/utils/loadPlugin.test.js index e4e188732a..c7aaf6f6f9 100644 --- a/@commitlint/load/src/utils/loadPlugin.test.js +++ b/@commitlint/load/src/utils/loadPlugin.test.js @@ -1,80 +1,78 @@ -import test from 'ava'; -const proxyquire = require('proxyquire') - .noCallThru() - .noPreserveCache(); +import loadPlugin from './loadPlugin'; -test.beforeEach(t => { - const plugins = {}; - const plugin = {}; - const scopedPlugin = {}; - const stubbedLoadPlugin = proxyquire('./loadPlugin', { - 'commitlint-plugin-example': plugin, - '@scope/commitlint-plugin-example': scopedPlugin - }).default; - t.context.data = { - plugins, - plugin, - scopedPlugin, - stubbedLoadPlugin - }; +beforeEach(() => { + jest.mock('commitlint-plugin-example', () => ({example: true}), { + virtual: true + }); + jest.mock('@scope/commitlint-plugin-example', () => ({scope: true}), { + virtual: true + }); }); -test('should load a plugin when referenced by short name', t => { - const {stubbedLoadPlugin, plugins, plugin} = t.context.data; - stubbedLoadPlugin(plugins, 'example'); - t.is(plugins['example'], plugin); +afterEach(() => { + jest.restoreAllMocks(); }); -test('should load a plugin when referenced by long name', t => { - const {stubbedLoadPlugin, plugins, plugin} = t.context.data; - stubbedLoadPlugin(plugins, 'commitlint-plugin-example'); - t.is(plugins['example'], plugin); +test('should load a plugin when referenced by short name', () => { + const plugins = {}; + loadPlugin(plugins, 'example'); + expect(plugins['example']).toBe(require('commitlint-plugin-example')); }); -test('should throw an error when a plugin has whitespace', t => { - const {stubbedLoadPlugin, plugins} = t.context.data; - t.throws(() => { - stubbedLoadPlugin(plugins, 'whitespace '); - }, /Whitespace found in plugin name 'whitespace '/u); - t.throws(() => { - stubbedLoadPlugin(plugins, 'whitespace\t'); - }, /Whitespace found in plugin name/u); - t.throws(() => { - stubbedLoadPlugin(plugins, 'whitespace\n'); - }, /Whitespace found in plugin name/u); - t.throws(() => { - stubbedLoadPlugin(plugins, 'whitespace\r'); - }, /Whitespace found in plugin name/u); +test('should load a plugin when referenced by long name', () => { + const plugins = {}; + loadPlugin(plugins, 'commitlint-plugin-example'); + expect(plugins['example']).toBe(require('commitlint-plugin-example')); }); -test("should throw an error when a plugin doesn't exist", t => { - const {stubbedLoadPlugin, plugins} = t.context.data; - t.throws(() => { - stubbedLoadPlugin(plugins, 'nonexistentplugin'); - }, /Failed to load plugin/u); +test('should throw an error when a plugin has whitespace', () => { + const plugins = {}; + expect(() => loadPlugin(plugins, 'whitespace ')).toThrow( + "Whitespace found in plugin name 'whitespace '" + ); + expect(() => loadPlugin(plugins, 'whitespace\t')).toThrow( + 'Whitespace found in plugin name' + ); + expect(() => loadPlugin(plugins, 'whitespace\n')).toThrow( + 'Whitespace found in plugin name' + ); + expect(() => loadPlugin(plugins, 'whitespace\r')).toThrow( + 'Whitespace found in plugin name' + ); }); -test('should load a scoped plugin when referenced by short name', t => { - const {stubbedLoadPlugin, plugins, scopedPlugin} = t.context.data; - stubbedLoadPlugin(plugins, '@scope/example'); - t.is(plugins['@scope/example'], scopedPlugin); +test("should throw an error when a plugin doesn't exist", () => { + const plugins = {}; + expect(() => loadPlugin(plugins, 'nonexistentplugin')).toThrow( + 'Failed to load plugin' + ); }); -test('should load a scoped plugin when referenced by long name', t => { - const {stubbedLoadPlugin, plugins, scopedPlugin} = t.context.data; - stubbedLoadPlugin(plugins, '@scope/commitlint-plugin-example'); - t.is(plugins['@scope/example'], scopedPlugin); +test('should load a scoped plugin when referenced by short name', () => { + const plugins = {}; + loadPlugin(plugins, '@scope/example'); + expect(plugins['@scope/example']).toBe( + require('@scope/commitlint-plugin-example') + ); +}); + +test('should load a scoped plugin when referenced by long name', () => { + const plugins = {}; + loadPlugin(plugins, '@scope/commitlint-plugin-example'); + expect(plugins['@scope/example']).toBe( + require('@scope/commitlint-plugin-example') + ); }); /* when referencing a scope plugin and omitting @scope/ */ -test("should load a scoped plugin when referenced by short name, but should not get the plugin if '@scope/' is omitted", t => { - const {stubbedLoadPlugin, plugins} = t.context.data; - stubbedLoadPlugin(plugins, '@scope/example'); - t.is(plugins['example'], undefined); +test("should load a scoped plugin when referenced by short name, but should not get the plugin if '@scope/' is omitted", () => { + const plugins = {}; + loadPlugin(plugins, '@scope/example'); + expect(plugins['example']).toBe(undefined); }); -test("should load a scoped plugin when referenced by long name, but should not get the plugin if '@scope/' is omitted", t => { - const {stubbedLoadPlugin, plugins} = t.context.data; - stubbedLoadPlugin(plugins, '@scope/commitlint-plugin-example'); - t.is(plugins['example'], undefined); +test("should load a scoped plugin when referenced by long name, but should not get the plugin if '@scope/' is omitted", () => { + const plugins = {}; + loadPlugin(plugins, '@scope/commitlint-plugin-example'); + expect(plugins['example']).toBe(undefined); }); diff --git a/jest.config.js b/jest.config.js index 28a58f4c92..fc4f98d807 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,7 +4,8 @@ module.exports = { testRegex: undefined, testMatch: [ '**/*.test.ts?(x)', - '**/@commitlint/read/src/*.test.js?(x)', - '**/@commitlint/cli/src/*.test.js?(x)' + '**/@commitlint/read/src/**/*.test.js?(x)', + '**/@commitlint/load/src/**/*.test.js?(x)', + '**/@commitlint/cli/src/**/*.test.js?(x)' ] }; diff --git a/yarn.lock b/yarn.lock index 32df2547ef..006408dca5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4370,14 +4370,6 @@ filename-regex@^2.0.0: resolved "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26" integrity sha1-wcS5vuPglyXdsQa3XB4wH+LxiyY= -fill-keys@^1.0.2: - version "1.0.2" - resolved "https://registry.npmjs.org/fill-keys/-/fill-keys-1.0.2.tgz#9a8fa36f4e8ad634e3bf6b4f3c8882551452eb20" - integrity sha1-mo+jb06K1jTjv2tPPIiCVRRS6yA= - dependencies: - is-object "~1.0.1" - merge-descriptors "~1.0.0" - fill-range@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7" @@ -5627,11 +5619,6 @@ is-obj@^2.0.0: resolved "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz#473fb05d973705e3fd9620545018ca8e22ef4982" integrity sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w== -is-object@~1.0.1: - version "1.0.1" - resolved "https://registry.npmjs.org/is-object/-/is-object-1.0.1.tgz#8952688c5ec2ffd6b03ecc85e769e02903083470" - integrity sha1-iVJojF7C/9awPsyF52ngKQMINHA= - is-observable@^1.1.0: version "1.1.0" resolved "https://registry.npmjs.org/is-observable/-/is-observable-1.1.0.tgz#b3e986c8f44de950867cab5403f5a3465005975e" @@ -6938,11 +6925,6 @@ meow@^3.3.0: redent "^1.0.0" trim-newlines "^1.0.0" -merge-descriptors@~1.0.0: - version "1.0.1" - resolved "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" - integrity sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E= - merge-stream@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" @@ -7124,11 +7106,6 @@ modify-values@^1.0.0: resolved "https://registry.npmjs.org/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022" integrity sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw== -module-not-found-error@^1.0.1: - version "1.0.1" - resolved "https://registry.npmjs.org/module-not-found-error/-/module-not-found-error-1.0.1.tgz#cf8b4ff4f29640674d6cdd02b0e3bc523c2bbdc0" - integrity sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA= - moment@2.19.3: version "2.19.3" resolved "https://registry.npmjs.org/moment/-/moment-2.19.3.tgz#bdb99d270d6d7fda78cc0fbace855e27fe7da69f" @@ -8153,15 +8130,6 @@ protoduck@^5.0.1: dependencies: genfun "^5.0.0" -proxyquire@2.1.3: - version "2.1.3" - resolved "https://registry.npmjs.org/proxyquire/-/proxyquire-2.1.3.tgz#2049a7eefa10a9a953346a18e54aab2b4268df39" - integrity sha512-BQWfCqYM+QINd+yawJz23tbBM40VIGXOdDw3X344KcclI/gtBbdWF6SlQ4nK/bYhF9d27KYug9WzljHC6B9Ysg== - dependencies: - fill-keys "^1.0.2" - module-not-found-error "^1.0.1" - resolve "^1.11.1" - pseudomap@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" @@ -8705,7 +8673,7 @@ resolve@1.1.7: resolved "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs= -resolve@1.x, resolve@^1.1.6, resolve@^1.10.0, resolve@^1.11.1, resolve@^1.3.2, resolve@^1.8.1: +resolve@1.x, resolve@^1.1.6, resolve@^1.10.0, resolve@^1.3.2, resolve@^1.8.1: version "1.14.1" resolved "https://registry.npmjs.org/resolve/-/resolve-1.14.1.tgz#9e018c540fcf0c427d678b9931cbf45e984bcaff" integrity sha512-fn5Wobh4cxbLzuHaE+nphztHy43/b++4M6SsGFC2gB8uYwf0C8LcarfCz1un7UTW8OFQg9iNjZ4xpcFVGebDPg==