Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const test = require('ava').default
const FP = require('../')
// const FP = require('../index.d.ts')
const chalk = require('chalk').default
///
test('Can FP.quiet() Error', t => {
t.plan(1)
return FP.resolve([1, 2, 3, 4])
.quiet(42)
.map((n) => {
if (n === 4) {
return Promise.reject(new TypeError('#4 found, dummy error!'))
}
return n
})
.then((results) => {
t.truthy(results[3] instanceof TypeError)
})
.catch(err => {
console.warn(chalk.yellowBright`ERR:`, err.message)
t.fail('shouldnt get here')
})
});
test('should remove console reporters in silent mode', (t: ExecutionContext) => {
cli.silent = true;
cli.reporters = 'console';
const options: IOptions = prepareOptions(cli);
t.deepEqual(options.reporters, ['silent', 'time']);
});
test('should add reporter for threshold', (t: ExecutionContext) => {
cli.threshold = true;
const options: IOptions = prepareOptions(cli);
t.truthy(options.reporters && options.reporters.includes('threshold'));
});
test('should create formats from string parameter', (t: ExecutionContext) => {
cli.formatsExts = 'javascript:ww,ss;dart:dd,zz';
const options: IOptions = prepareOptions(cli);
console.log(options.formatsExts);
t.deepEqual(options.formatsExts, {
dart: ['dd', 'zz'],
javascript: ['ww', 'ss']
});
});
.catchIf(TypeError, () => t.pass('successfully filtered .catch(type)'))
.catch(err => t.fail(err.message === 'Oh noes'))
})
test('Does .catch(filterType, fn) filtering by TypeError', t => {
return FP.resolve()
.then(() => {throw new Error('Oh noes')})
.tap(() => t.fail('must skip to the .catch section!'))
.catch(TypeError, () => t.fail('arg too specific for .catch(type)'))
.catch(SyntaxError, () => t.fail('arg too specific for .catch(type)'))
.catch(ReferenceError, () => t.fail('arg too specific for .catch(type)'))
.catch(err => t.truthy(err.message === 'Oh noes'))
})
test('Does .catch(filterType, fn) skip negative tests', t => {
return FP.resolve()
.then(() => {throw new TypeError('Oh noes')})
.tap(() => t.fail('must skip to the .catch section!'))
.catch(ReferenceError, () => t.fail('arg too specific for .catch(type)'))
.catch(SyntaxError, () => t.fail('arg too specific for .catch(type)'))
.catch(TypeError, () => t.pass('successfully filtered .catch(type)'))
.catch(err => t.fail(err.message === 'Oh noes'))
})
test('Can override .catch() w/ .chain()', t => {
const pipeline = FP.chain()
.map(() => FP.reject(new Error('Fail!')))
.chainEnd()
return pipeline([1])
.then(result => {
test("cli-write", t => {
const { input, expected } = importerTests.find(t => t.name === "append-all");
const inputPath = path.join(os.tmpdir(), "test-cli-write.js");
return writeFile(inputPath, input)
.then(() => cli(["-w", inputPath]))
.then(({ stdout, code }) => {
t.is(stdout, "");
t.is(code, 0);
return readFile(inputPath, "utf8");
})
.then(actual => t.is(actual, expected));
});
test("cli-stdin", t => {
const { input, expected } = importerTests.find(
t => t.name === "import-default-prop"
);
return cli(["-s", __dirname], input).then(({ stdout, code }) => {
t.is(stdout, expected);
t.is(code, 0);
});
});
test("cli-write-stdin", t => {
const { input, expected } = importerTests.find(
t => t.name === "import-multi-ident"
);
const outputPath = path.join(os.tmpdir(), "test-cli-write-stdin.js");
return cli(["-s", "-w", outputPath], input)
.tap(() => t.fail('must skip to the .catch section!'))
.catch(err => ({message: 'temp error, plz try again', _err: err}))
.then(data => t.truthy(data.message === 'temp error, plz try again'))
})
test('Does .catchIf(filterType, fn) filtering by TypeError', t => {
return FP.resolve()
.then(() => {throw new Error('Oh noes')})
.tap(() => t.fail('must skip to the .catch section!'))
.catchIf(TypeError, () => t.fail('arg too specific for .catch(type)'))
.catchIf(SyntaxError, () => t.fail('arg too specific for .catch(type)'))
.catchIf(ReferenceError, () => t.fail('arg too specific for .catch(type)'))
.catch(err => t.truthy(err.message === 'Oh noes'))
})
test('Does .catchIf(filterType, fn) skip negative tests', t => {
return FP.resolve()
.then(() => {throw new TypeError('Oh noes')})
.tap(() => t.fail('must skip to the .catch section!'))
.catchIf(ReferenceError, () => t.fail('arg too specific for .catch(type)'))
.catchIf(SyntaxError, () => t.fail('arg too specific for .catch(type)'))
.catchIf(TypeError, () => t.pass('successfully filtered .catch(type)'))
.catch(err => t.fail(err.message === 'Oh noes'))
})
test('Does .catch(filterType, fn) filtering by TypeError', t => {
return FP.resolve()
.then(() => {throw new Error('Oh noes')})
.tap(() => t.fail('must skip to the .catch section!'))
.catch(TypeError, () => t.fail('arg too specific for .catch(type)'))
.catch(SyntaxError, () => t.fail('arg too specific for .catch(type)'))
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ava_1 = require("ava");
const utils_1 = require("../utils");
ava_1.default('getGlobalType, error.', t => {
t.throws(() => utils_1.getGlobalType(undefined));
t.throws(() => utils_1.getGlobalType(123));
t.throws(() => utils_1.getGlobalType(() => { }));
t.throws(() => utils_1.getGlobalType(function () { }));
t.throws(() => utils_1.getGlobalType(function test() { }));
});
ava_1.default('getGlobalType, string.', t => {
t.true(utils_1.getGlobalType('stringkey') === 'stringkey');
});
ava_1.default('getGlobalType, one class.', t => {
class A {
}
const typeA = utils_1.getGlobalType(A);
t.true(typeA === 'A');
});
ava_1.default('getSuperClassInfo.', t => {
class A {
}
class B extends A {
}
const typeAs = utils_1.getSuperClassInfo(A);
const typeBs = utils_1.getSuperClassInfo(B);
t.true(typeAs.length === 0);
const test = new ITestService;
t.true(test.testService instanceof DTestService);
});
ava_1.default('inject decorator, no data.', t => {
class NRService {
}
class ITestService {
}
__decorate([
inject(NRService),
__metadata("design:type", NRService)
], ITestService.prototype, "testService", void 0);
const test = new ITestService;
t.true(!test.testService);
});
ava_1.default('lazyInject decorator.', t => {
let DTestService = class DTestService {
};
DTestService = __decorate([
register()
], DTestService);
class LITestService {
}
__decorate([
lazyInject(DTestService),
__metadata("design:type", DTestService)
], LITestService.prototype, "testService", void 0);
const test = new LITestService;
t.true(test.testService instanceof DTestService);
});
ava_1.default('lazyInject decorator, no data.', t => {
class NRService {
t.true(IocContext_1.IocContext.DefaultInstance instanceof IocContext_1.IocContext);
});
ava_1.default('register component error case.', t => {
var INJECTTYPE;
(function (INJECTTYPE) {
INJECTTYPE[INJECTTYPE["test"] = 0] = "test";
})(INJECTTYPE || (INJECTTYPE = {}));
const context = new IocContext_1.IocContext;
t.throws(() => context.register(undefined));
t.throws(() => context.register(123123));
t.throws(() => context.register({}));
t.throws(() => context.register({}, 123123));
t.throws(() => context.register({}, INJECTTYPE.test));
t.throws(() => context.register('33333', undefined, { regInSuperClass: true }));
});
ava_1.default('register component by class.', t => {
const context = new IocContext_1.IocContext;
context.register(TestService);
t.true(context.get(TestService) instanceof TestService);
});
ava_1.default('register component mutli-instance.', t => {
const context = new IocContext_1.IocContext;
context.register(TestService, undefined, { singleton: false });
const dataA = context.get(TestService);
t.true(dataA instanceof TestService);
const dataB = context.get(TestService);
t.true(dataB instanceof TestService);
t.false(dataA === dataB);
});
ava_1.default('register component no autonew.', t => {
const context = new IocContext_1.IocContext;
context.register(TestService, undefined, { autoNew: false });
}
class BClass extends AClass {
}
class CClass extends AClass {
}
const context = new IocContext_1.IocContext;
t.true(!context.getSubClasses(AClass));
context.register(BClass, undefined, { regInSuperClass: true });
context.register(CClass, undefined, { regInSuperClass: true });
const cls = context.getSubClasses(AClass);
t.true(cls.length === 2);
t.true(cls[0] instanceof BClass);
t.true(cls[1] instanceof CClass);
t.false(!context.get(AClass));
});
ava_1.default('getSubClasses, diff options.', t => {
class AClass {
}
class BClass extends AClass {
}
class CClass extends AClass {
}
const context = new IocContext_1.IocContext;
context.register(BClass, undefined, { regInSuperClass: true });
context.register(CClass, undefined, { singleton: false, regInSuperClass: true });
const cls1 = context.getSubClasses(AClass);
const cls2 = context.getSubClasses(AClass);
t.true(cls1[0] === cls2[0]);
t.true(cls1[1] !== cls2[1]);
});
ava_1.default('getSubClasses, mutli.', t => {
class AClass {
const decorator = new helper_1.Decorators();
let NRService = class NRService {
};
NRService = __decorate([
decorator.register()
], NRService);
class LITestService {
}
__decorate([
decorator.lazyInject(NRService),
__metadata("design:type", NRService)
], LITestService.prototype, "testService", void 0);
const test = new LITestService;
t.true(test.testService instanceof NRService);
});
ava_1.default('register decorator.', t => {
let DTestService = class DTestService {
};
DTestService = __decorate([
register()
], DTestService);
t.true(context.get(DTestService) instanceof DTestService);
});
ava_1.default('inject decorator.', t => {
let DTestService = class DTestService {
};
DTestService = __decorate([
register()
], DTestService);
class ITestService {
}
__decorate([