fix: more ES imports, some corresponding import changes, reset mock FS after every test
This commit is contained in:
parent
5221258d26
commit
052ca736d2
|
@ -1,5 +1,6 @@
|
|||
import { createLogger } from 'bunyan';
|
||||
import { showCompletionScript } from 'yargs';
|
||||
import yargs from 'yargs';
|
||||
const { showCompletionScript } = yargs;
|
||||
|
||||
import { loadConfig } from './config/index.js';
|
||||
import { CONFIG_ARGS_NAME, CONFIG_ARGS_PATH, MODE, parseArgs } from './config/args.js';
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Options, usage } from 'yargs';
|
||||
import yargs, { Options } from 'yargs';
|
||||
const { usage } = yargs;
|
||||
|
||||
import { RuleSelector, RuleSources } from '../rule/index.js';
|
||||
import { VERSION_INFO } from '../version.js';
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import { hasItems } from '@apextoaster/js-utils';
|
||||
import { applyDiff, diff } from 'deep-diff';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import deepDiff from 'deep-diff';
|
||||
const { applyDiff, diff } = deepDiff;
|
||||
import lodash from 'lodash';
|
||||
const { cloneDeep } = lodash;
|
||||
|
||||
import { Rule } from './index.js';
|
||||
import { Visitor } from '../visitor/index.js';
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import { doesExist, hasItems } from '@apextoaster/js-utils';
|
||||
import { ErrorObject, ValidateFunction } from 'ajv';
|
||||
import { cloneDeep, defaultTo } from 'lodash';
|
||||
import { LogLevel } from 'noicejs';
|
||||
|
||||
import { Rule, RuleData } from './index.js';
|
||||
import { Visitor, VisitorError, VisitorResult } from '../visitor/index.js';
|
||||
import { VisitorContext } from '../visitor/VisitorContext.js';
|
||||
|
||||
import lodash from 'lodash';
|
||||
const { cloneDeep, defaultTo } = lodash;
|
||||
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/strict-boolean-expressions */
|
||||
|
||||
const DEFAULT_FILTER = () => true;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { doesExist, ensureArray } from '@apextoaster/js-utils';
|
||||
import { ValidateFunction } from 'ajv';
|
||||
import { intersection } from 'lodash';
|
||||
import { Minimatch } from 'minimatch';
|
||||
import lodash from 'lodash';
|
||||
const { intersection } = lodash;
|
||||
import minimatch from 'minimatch';
|
||||
const { Minimatch } = minimatch;
|
||||
import { LogLevel } from 'noicejs';
|
||||
|
||||
// import ruleSchemaData from '../../rules/salty-dog.yml';
|
||||
|
|
|
@ -28,6 +28,12 @@ export function setFs(fs: Filesystem) {
|
|||
};
|
||||
}
|
||||
|
||||
export function resetFs() {
|
||||
readdir = promises.readdir;
|
||||
readFile = promises.readFile;
|
||||
writeFile = promises.writeFile;
|
||||
}
|
||||
|
||||
export async function listFiles(path: string): Promise<Array<string>> {
|
||||
const dirs: Array<string> = [path];
|
||||
const files: Array<string> = [];
|
||||
|
|
|
@ -2,7 +2,7 @@ import { expect } from 'chai';
|
|||
import { vol } from 'memfs';
|
||||
|
||||
import { main, STATUS_ERROR, STATUS_SUCCESS } from '../src/app.js';
|
||||
import { Filesystem, readSource, setFs } from '../src/source.js';
|
||||
import { Filesystem, readSource, resetFs, setFs } from '../src/source.js';
|
||||
|
||||
const TEST_ARGS_PRE = ['node', 'test'];
|
||||
const TEST_ARGS_CONFIG = ['--config-path', 'docs', '--config-name', 'config.yml'];
|
||||
|
@ -39,6 +39,10 @@ describe('main app', async () => {
|
|||
vol.reset();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
resetFs();
|
||||
});
|
||||
|
||||
it('completion should succeed', async () => {
|
||||
const status = await main(['node', 'test', 'complete']);
|
||||
expect(status).to.equal(STATUS_SUCCESS);
|
||||
|
|
|
@ -2,10 +2,10 @@ import { NotFoundError } from '@apextoaster/js-utils';
|
|||
import { expect } from 'chai';
|
||||
import { join } from 'path';
|
||||
|
||||
import { loadConfig, readConfig } from '../../src/config';
|
||||
import { loadConfig, readConfig } from '../../src/config/index.js';
|
||||
|
||||
describe('load config helper', async () => {
|
||||
it('should load an existing config', () =>
|
||||
it('should load an existing config', async () =>
|
||||
expect(loadConfig('config-stderr.yml', join(__dirname, '..', 'docs'))).to.eventually.deep.include({
|
||||
data: {
|
||||
logger: {
|
||||
|
@ -17,11 +17,11 @@ describe('load config helper', async () => {
|
|||
})
|
||||
);
|
||||
|
||||
it('should throw when config is missing', () =>
|
||||
it('should throw when config is missing', async () =>
|
||||
expect(loadConfig('missing.yml', join(__dirname, '..', 'docs'))).to.eventually.be.rejectedWith(NotFoundError)
|
||||
);
|
||||
|
||||
it('should load included config', () =>
|
||||
it('should load included config', async () =>
|
||||
expect(loadConfig('config-include.yml', join(__dirname, '..', 'docs'))).to.eventually.deep.include({
|
||||
data: {
|
||||
include: {
|
||||
|
@ -33,11 +33,11 @@ describe('load config helper', async () => {
|
|||
});
|
||||
|
||||
describe('read config helper', async () => {
|
||||
it('should consume enoent errors', () =>
|
||||
it('should consume enoent errors', async () =>
|
||||
expect(readConfig(join('docs', 'missing.yml'))).to.eventually.equal(undefined)
|
||||
);
|
||||
|
||||
it('should rethrow unknown errors', () =>
|
||||
it('should rethrow unknown errors', async () =>
|
||||
expect(readConfig('test')).to.eventually.be.rejectedWith(Error)
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { expect } from 'chai';
|
||||
|
||||
import { YamlParser } from '../../src/parser/YamlParser';
|
||||
import { YamlParser } from '../../src/parser/YamlParser.js';
|
||||
|
||||
describe('yaml parser', () => {
|
||||
describe('dump documents', () => {
|
||||
it('should dump multiple documents', () => {
|
||||
it('should dump multiple documents', async () => {
|
||||
const parser = new YamlParser();
|
||||
const data = parser.dump({}, {});
|
||||
|
||||
|
@ -13,7 +13,7 @@ describe('yaml parser', () => {
|
|||
});
|
||||
|
||||
describe('parse documents', () => {
|
||||
it('should parse multiple documents', () => {
|
||||
it('should parse multiple documents', async () => {
|
||||
const parser = new YamlParser();
|
||||
const data = parser.parse(`
|
||||
foo: {}
|
||||
|
|
|
@ -3,10 +3,10 @@ import { vol } from 'memfs';
|
|||
import { LogLevel, NullLogger } from 'noicejs';
|
||||
import { spy, stub } from 'sinon';
|
||||
|
||||
import { loadRuleFiles, loadRuleModules, loadRulePaths, loadRuleSource } from '../../src/rule';
|
||||
import { SchemaRule } from '../../src/rule/SchemaRule';
|
||||
import { Filesystem, setFs } from '../../src/source';
|
||||
import { VisitorContext } from '../../src/visitor/VisitorContext';
|
||||
import { loadRuleFiles, loadRuleModules, loadRulePaths, loadRuleSource } from '../../src/rule/index.js';
|
||||
import { SchemaRule } from '../../src/rule/SchemaRule.js';
|
||||
import { Filesystem, setFs } from '../../src/source.js';
|
||||
import { VisitorContext } from '../../src/visitor/VisitorContext.js';
|
||||
|
||||
const EXAMPLE_EMPTY = '{name: foo, definitions: {}, rules: []}';
|
||||
const EXAMPLE_RULES = `{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { expect } from 'chai';
|
||||
import { ConsoleLogger, LogLevel, NullLogger } from 'noicejs';
|
||||
|
||||
import { createRuleSelector, createRuleSources, resolveRules, validateRules } from '../../src/rule';
|
||||
import { SchemaRule } from '../../src/rule/SchemaRule';
|
||||
import { VisitorContext } from '../../src/visitor/VisitorContext';
|
||||
import { createRuleSelector, createRuleSources, resolveRules, validateRules } from '../../src/rule/index.js';
|
||||
import { SchemaRule } from '../../src/rule/SchemaRule.js';
|
||||
import { VisitorContext } from '../../src/visitor/VisitorContext.js';
|
||||
|
||||
const TEST_RULES = [new SchemaRule({
|
||||
check: {},
|
||||
|
@ -118,7 +118,7 @@ describe('rule resolver', async () => {
|
|||
});
|
||||
|
||||
describe('create rule sources helper', () => {
|
||||
it('should ensure every field is an array', () => {
|
||||
it('should ensure every field is an array', async () => {
|
||||
const sources = createRuleSources({});
|
||||
|
||||
expect(sources).to.have.deep.property('ruleFile', []);
|
||||
|
@ -128,7 +128,7 @@ describe('create rule sources helper', () => {
|
|||
});
|
||||
|
||||
describe('create rule selector helper', () => {
|
||||
it('should ensure every field is an array', () => {
|
||||
it('should ensure every field is an array', async () => {
|
||||
const sources = createRuleSelector({});
|
||||
|
||||
expect(sources).to.have.deep.property('excludeLevel', []);
|
||||
|
|
|
@ -2,9 +2,9 @@ import { expect } from 'chai';
|
|||
import { LogLevel, NullLogger } from 'noicejs';
|
||||
import { mock, spy, stub } from 'sinon';
|
||||
|
||||
import { RuleVisitor } from '../../src/rule/RuleVisitor';
|
||||
import { SchemaRule } from '../../src/rule/SchemaRule';
|
||||
import { VisitorContext } from '../../src/visitor/VisitorContext';
|
||||
import { RuleVisitor } from '../../src/rule/RuleVisitor.js';
|
||||
import { SchemaRule } from '../../src/rule/SchemaRule.js';
|
||||
import { VisitorContext } from '../../src/visitor/VisitorContext.js';
|
||||
|
||||
describe('rule visitor', async () => {
|
||||
it('should only call visit for selected items', async () => {
|
||||
|
|
|
@ -2,8 +2,8 @@ import { expect } from 'chai';
|
|||
import { LogLevel, NullLogger } from 'noicejs';
|
||||
import { stub } from 'sinon';
|
||||
|
||||
import { friendlyError, SchemaRule } from '../../src/rule/SchemaRule';
|
||||
import { VisitorContext } from '../../src/visitor/VisitorContext';
|
||||
import { friendlyError, SchemaRule } from '../../src/rule/SchemaRule.js';
|
||||
import { VisitorContext } from '../../src/visitor/VisitorContext.js';
|
||||
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
|
@ -208,7 +208,7 @@ function createErrorContext() {
|
|||
}
|
||||
|
||||
describe('friendly errors', () => {
|
||||
it('should have a message', () => {
|
||||
it('should have a message', async () => {
|
||||
const { ctx } = createErrorContext();
|
||||
const err = friendlyError(ctx, {
|
||||
instancePath: 'test-path',
|
||||
|
@ -219,7 +219,7 @@ describe('friendly errors', () => {
|
|||
expect(err.msg).to.include(TEST_NAME);
|
||||
});
|
||||
|
||||
it('should handle errors with an existing message', () => {
|
||||
it('should handle errors with an existing message', async () => {
|
||||
const { ctx } = createErrorContext();
|
||||
const TEST_MESSAGE = 'test-message';
|
||||
const err = friendlyError(ctx, {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { expect } from 'chai';
|
||||
import { LogLevel, NullLogger } from 'noicejs';
|
||||
|
||||
import { VisitorContext } from '../../src/visitor/VisitorContext';
|
||||
import { VisitorContext } from '../../src/visitor/VisitorContext.js';
|
||||
|
||||
describe('visitor context', () => {
|
||||
it('should merge results', () => {
|
||||
it('should merge results', async () => {
|
||||
const firstCtx = new VisitorContext({
|
||||
logger: NullLogger.global,
|
||||
schemaOptions: {
|
||||
|
|
Loading…
Reference in New Issue