Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/test

Package Overview
Dependencies
Maintainers
1
Versions
352
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/test - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

2

package.json

@@ -28,3 +28,3 @@ {

},
"version": "0.0.10"
"version": "0.0.11"
}

@@ -20,3 +20,3 @@ import * as child_process from 'child_process';

let [sub, forked] = fork(this.command, {
const [sub, forked] = fork(this.command, {
env: {

@@ -72,3 +72,3 @@ ...process.env,

listenOnce(type: string, callback: (data: any) => void) {
let fn = (e: any) => {
const fn = (e: any) => {
if (e.type === type) {

@@ -75,0 +75,0 @@ this.process.removeListener('message', fn);

@@ -17,3 +17,3 @@ import * as os from 'os';

for (let i = 0; i < this.agentCount; i++) {
let agent = new Agent(i, this.command);
const agent = new Agent(i, this.command);
this.availableAgents.add(agent);

@@ -32,3 +32,3 @@ }

} else {
let agent = this.availableAgents.values().next().value;
const agent = this.availableAgents.values().next().value;
this.availableAgents.delete(agent);

@@ -50,8 +50,8 @@ await agent.init();

let position = 0;
let errors: Error[] = [];
const errors: Error[] = [];
while (position < inputs.length) {
if (this.pendingAgents.size < this.availableSize) {
let next = position++;
let agent = (await this.getNextAgent())!;
const next = position++;
const agent = (await this.getNextAgent())!;

@@ -61,4 +61,4 @@ agent.completion = new Promise<Agent>((resolve, reject) => {

if (e) {
let err: any = new Error();
for (let k of Object.keys(e)) {
const err: any = new Error();
for (const k of Object.keys(e)) {
err[k] = e[k];

@@ -82,3 +82,3 @@ }

} else {
let agent = await Promise.race(Array.from(this.pendingAgents).map(x => x.completion));
const agent = await Promise.race(Array.from(this.pendingAgents).map(x => x.completion));
this.returnAgent(agent);

@@ -94,7 +94,7 @@ }

shutdown() {
for (let agent of Array.from(this.pendingAgents)) {
for (const agent of Array.from(this.pendingAgents)) {
this.returnAgent(agent);
}
for (let agent of Array.from(this.availableAgents)) {
for (const agent of Array.from(this.availableAgents)) {
if (agent.process) {

@@ -101,0 +101,0 @@ try {

@@ -16,2 +16,10 @@ import { AppEnv } from '@travetto/base';

function clean(val: any) {
if (val === null || val === undefined || typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean' || _.isPlainObject(val)) {
return val;
} else {
return `${val}`;
}
}
export class AssertUtil {

@@ -22,4 +30,4 @@

static readFilePosition(err: Error, filename: string) {
let base = process.cwd();
let lines = (err.stack || new Error().stack!).split('\n').filter(x => !x.includes('/node_modules/') && x.includes(base));
const base = process.cwd();
const lines = (err.stack || new Error().stack!).split('\n').filter(x => !x.includes('/node_modules/') && x.includes(base));
let best = lines.filter(x => x.includes(filename))[0];

@@ -35,8 +43,8 @@

let [fn, path] = best.trim().split(/\s+/g).slice(1);
let [file, lineNo, col] = path.replace(/[()]/g, '').split(':')
const [fn, path] = best.trim().split(/\s+/g).slice(1);
const [file, lineNo, col] = path.replace(/[()]/g, '').split(':')
file = file.split(process.cwd() + '/')[1];
const outFile = file.split(process.cwd() + '/')[1];
let res = { file, line: parseInt(lineNo, 10) };
const res = { file: outFile, line: parseInt(lineNo, 10) };

@@ -51,5 +59,5 @@ return res;

static check(filename: string, text: string, name: string, ...args: any[]) {
let { file, line } = this.readFilePosition(new Error(), filename.replace(/[.][tj]s$/, ''));
const { file, line } = this.readFilePosition(new Error(), filename.replace(/[.][tj]s$/, ''));
let assertion: Assertion = { file, line, text, operator: ASSERT_FN_OPERATOR[name] };
const assertion: Assertion = { file, line, text, operator: ASSERT_FN_OPERATOR[name] };
if (name === 'fail') {

@@ -94,2 +102,11 @@ if (args.length > 1) {

}
if (assertion.actual) {
assertion.actual = clean(assertion.actual);
}
if (assertion.expected) {
assertion.expected = clean(assertion.expected);
}
// Pushing on not error

@@ -101,3 +118,3 @@ this.asserts.push(assertion);

if (assertion.operator) {
let op = name.includes('hrow') ?
const op = name.includes('hrow') ?
`should ${assertion.operator}` :

@@ -107,3 +124,3 @@ `should be ${assertion.operator}`;

} else {
assertion.message = `should be ${assertion.expected}`;
assertion.message = `should be ${clean(assertion.expected)}`;
}

@@ -119,3 +136,3 @@ }

static end() {
let ret = this.asserts;
const ret = this.asserts;
this.asserts = [];

@@ -122,0 +139,0 @@ return ret;

@@ -16,3 +16,3 @@ import * as util from 'util';

static log(level: string, ...args: any[]) {
let msg = args.map((x: any) => typeof x === 'string' ? x : util.inspect(x, false, 4)).join(' ');
const msg = args.map((x: any) => typeof x === 'string' ? x : util.inspect(x, false, 4)).join(' ');
this.out[level] = (this.out[level] || '') + msg + '\n';

@@ -23,3 +23,3 @@ }

this.out = {};
for (let level of Object.keys(OG_CONSOLE)) {
for (const level of Object.keys(OG_CONSOLE)) {
(console as any)[level] = this.log.bind(this, level);

@@ -30,5 +30,5 @@ }

static end() {
let ret = this.out;
const ret = this.out;
this.out = {};
for (let level of Object.keys(OG_CONSOLE)) {
for (const level of Object.keys(OG_CONSOLE)) {
(console as any)[level] = (OG_CONSOLE as any)[level];

@@ -35,0 +35,0 @@ }

@@ -26,3 +26,3 @@ import * as yaml from 'js-yaml';

if (e.type === 'test' && e.phase === 'after') {
let { test } = e;
const { test } = e;
let header = `${test.suiteName} - ${test.method}`;

@@ -33,7 +33,7 @@ if (test.description) {

this.log(`# ${header}`);
let message = '';
if (test.assertions.length) {
let subCount = 0;
let count = test.assertions.length;
for (let a of test.assertions) {
const count = test.assertions.length;
for (const a of test.assertions) {
let subMessage = `ok ${++subCount} - ${a.text} ${a.file}:${a.line}`;

@@ -62,3 +62,3 @@ if (a.error) {

if (test.output) {
for (let key of ['log', 'info', 'error', 'debug', 'warn']) {
for (const key of ['log', 'info', 'error', 'debug', 'warn']) {
if (test.output[key]) {

@@ -76,3 +76,3 @@ this.logMeta({ [key]: test.output[key] });

this.log('---\n');
for (let err of collector.errors) {
for (const err of collector.errors) {
this.log(err.toString());

@@ -79,0 +79,0 @@ }

@@ -6,2 +6,3 @@ import * as minimist from 'minimist';

import { TestUtil } from './test';
import { AllSuitesResult } from '../model/suite';

@@ -47,3 +48,3 @@ interface State {

let formatter = this.state.format;
const formatter = this.state.format;

@@ -63,3 +64,3 @@ const collector = new Collector();

for (let l of listeners) {
for (const l of listeners) {
l.onEvent = l.onEvent.bind(l);

@@ -70,7 +71,7 @@ }

let agentPool = new AgentPool(require.resolve('../../bin/worker.js'));
const agentPool = new AgentPool(require.resolve('../../bin/worker.js'));
collector.errors = await agentPool.process(files, async (file, run, agent) => {
if (agent) {
for (let l of listeners) {
for (const l of listeners) {
agent.listen(l.onEvent);

@@ -82,3 +83,3 @@ }

for (let listener of listeners) {
for (const listener of listeners) {
if ((listener as any).onComplete) {

@@ -92,3 +93,3 @@ (listener as CollectionComplete).onComplete(collector);

if (formatter && formatter !== 'noop') {
let fn = require('./formatter/' + formatter)
const fn = require('./formatter/' + formatter) as { [key: string]: (all: AllSuitesResult) => string | undefined };
output = Object.values(fn)[0](collector.allSuites);

@@ -95,0 +96,0 @@ }

@@ -22,4 +22,4 @@ import * as fs from 'fs';

return new Promise<boolean>((resolve, reject) => {
let input = fs.createReadStream(file);
let reader = readline.createInterface({ input })
const input = fs.createReadStream(file);
const reader = readline.createInterface({ input })
.on('line', line => {

@@ -37,4 +37,4 @@ if (line.includes('@Suite')) {

static async getTests(globs: string[]) {
let files = await bulkFind(globs);
let all = await Promise.all(files.map(async (f) => [f, await this.isTest(f)] as [string, boolean]));
const files = await bulkFind(globs);
const all = await Promise.all(files.map(async (f) => [f, await this.isTest(f)] as [string, boolean]));
return all.filter(x => x[1]).map(x => x[0]);

@@ -68,4 +68,4 @@ }

static async executeTest(test: TestConfig) {
let suite = TestRegistry.get(test.class);
let result: Partial<TestResult> = {
const suite = TestRegistry.get(test.class);
const result: Partial<TestResult> = {
method: test.method,

@@ -89,4 +89,4 @@ description: test.description,

let timeout = new Promise((_, reject) => setTimeout(reject, this.timeout).unref());
let res = await Promise.race([suite.instance[test.method](), timeout]);
const timeout = new Promise((_, reject) => setTimeout(reject, this.timeout).unref());
const res = await Promise.race([suite.instance[test.method](), timeout]);
result.status = 'success';

@@ -107,5 +107,5 @@ } catch (err) {

if (result.status === 'fail' && result.error) {
let err = result.error;
const err = result.error;
if (!(err instanceof assert.AssertionError)) {
let { file, line } = AssertUtil.readFilePosition(err, test.file);
const { file, line } = AssertUtil.readFilePosition(err, test.file);
const assertion: Assertion = { file, line, operator: 'throws', text: '', error: err, message: `Error thrown: ${err.message}` };

@@ -121,7 +121,7 @@ result.assertions.push(assertion);

try {
for (let fn of suite[phase]) {
for (const fn of suite[phase]) {
await fn.call(suite.instance);
}
} catch (error) {
let { line, file } = AssertUtil.readFilePosition(error, suite.class.__filename);
const { line, file } = AssertUtil.readFilePosition(error, suite.class.__filename);
result.tests.push({

@@ -148,3 +148,3 @@ status: 'fail',

let test = {
const test = {
line: suite.line,

@@ -182,3 +182,3 @@ lineEnd: suite.lineEnd,

static async executeSuite(suite: SuiteConfig, emitter?: TestEmitter) {
let result: SuiteResult = {
const result: SuiteResult = {
success: 0,

@@ -199,3 +199,3 @@ fail: 0,

for (let test of suite.tests) {
for (const test of suite.tests) {
await this.affixProcess(suite, result, 'beforeEach');

@@ -207,3 +207,3 @@

let ret = await this.executeTest(test);
const ret = await this.executeTest(test);
result[ret.status]++;

@@ -237,6 +237,6 @@ result.tests.push(ret);

let classes = TestRegistry.getClasses();
const classes = TestRegistry.getClasses();
for (let cls of classes) {
let suite = TestRegistry.get(cls);
for (const cls of classes) {
const suite = TestRegistry.get(cls);

@@ -248,3 +248,3 @@ try {

let result = await this.executeSuite(suite, emitter);
const result = await this.executeSuite(suite, emitter);

@@ -251,0 +251,0 @@ if (emitter) {

@@ -25,3 +25,3 @@ import { MetadataRegistry, Class } from '@travetto/registry';

registerPendingListener<T>(cls: Class<T>, listener: Function, phase: 'beforeAll' | 'beforeEach' | 'afterAll' | 'afterEach', ) {
let suiteConfig = this.getOrCreatePending(cls)! as SuiteConfig;
const suiteConfig = this.getOrCreatePending(cls)! as SuiteConfig;
suiteConfig[phase].push(listener);

@@ -31,4 +31,4 @@ }

onInstallFinalize<T>(cls: Class<T>): SuiteConfig {
let config = this.getOrCreatePending(cls) as SuiteConfig;
let tests = this.pendingMethods.get(cls.__id)!.values();
const config = this.getOrCreatePending(cls) as SuiteConfig;
const tests = this.pendingMethods.get(cls.__id)!.values();
config.instance = new config.class();

@@ -39,3 +39,3 @@ config.tests = Array.from(tests) as TestConfig[];

}
for (let t of config.tests) {
for (const t of config.tests) {
t.suiteName = config.name;

@@ -42,0 +42,0 @@ }

@@ -9,5 +9,5 @@ import * as ts from 'typescript';

if (ts.isMethodDeclaration(node) || ts.isClassDeclaration(node)) {
let dec = TransformUtil.findAnyDecorator(node, {
'Test': new Set([TEST_IMPORT]),
'Suite': new Set([TEST_IMPORT])
const dec = TransformUtil.findAnyDecorator(node, {
Test: new Set([TEST_IMPORT]),
Suite: new Set([TEST_IMPORT])
}, state);

@@ -34,3 +34,3 @@

if (ts.isClassDeclaration(node)) {
for (let el of node.members) {
for (const el of node.members) {
if (!el.parent) {

@@ -52,3 +52,7 @@ el.parent = node;

// Only apply to test files
if (process.env.ENV === 'test' && source.fileName.includes('/test/') && !source.fileName.includes('/src/') && !source.fileName.includes('/node_modules/')) {
if (process.env.ENV === 'test' &&
source.fileName.includes('/test/') &&
!source.fileName.includes('/src/') &&
!source.fileName.includes('/node_modules/')
) {
// Annotate

@@ -55,0 +59,0 @@ return TRANSFORMER(context)(source);

@@ -45,3 +45,3 @@ import * as ts from 'typescript';

args = args.filter(x => x !== undefined && x !== null);
let check = ts.createCall(state.assertCheck, undefined, ts.createNodeArray([
const check = ts.createCall(state.assertCheck, undefined, ts.createNodeArray([
ts.createLiteral('__filename'),

@@ -53,3 +53,3 @@ ts.createLiteral(TransformUtil.getPrimaryArgument(node)!.getText()),

for (let arg of args) {
for (const arg of args) {
arg.parent = check;

@@ -79,3 +79,3 @@ }

if (ts.isCallExpression(node)) {
let exp: ts.Expression = node.expression;
const exp: ts.Expression = node.expression;
if (ts.isIdentifier(exp) && exp.getText() === ASSERT_CMD) {

@@ -91,3 +91,3 @@ replaced = true;

if (opFn) {
let literal = isDeepLiteral(comp.left) ? comp.left : isDeepLiteral(comp.right) ? comp.right : undefined;
const literal = isDeepLiteral(comp.left) ? comp.left : isDeepLiteral(comp.right) ? comp.right : undefined;
if (/equal/i.test(opFn) && literal) {

@@ -104,3 +104,3 @@ opFn = EQUALS_MAPPING[opFn] || opFn;

if (ts.isPrefixUnaryExpression(comp.operand)) {
let inner = comp.operand.operand;
const inner = comp.operand.operand;
node = doAssert(state, node, 'ok', [inner, message!]); // !!v

@@ -114,3 +114,3 @@ } else {

} else if (ts.isPropertyAccessExpression(exp) && ts.isIdentifier(exp.expression)) {
let ident = exp.expression;
const ident = exp.expression;
if (ident.escapedText === ASSERT_CMD) {

@@ -130,3 +130,3 @@ replaced = true;

if (ts.isClassDeclaration(node)) {
for (let el of node.members) {
for (const el of node.members) {
if (!el.parent) {

@@ -149,3 +149,7 @@ el.parent = node;

// Only apply to test files
if (process.env.ENV === 'test' && source.fileName.includes('/test/') && !source.fileName.includes('/src/') && !source.fileName.includes('/node_modules/')) {
if (process.env.ENV === 'test' &&
source.fileName.includes('/test/') &&
!source.fileName.includes('/src/') &&
!source.fileName.includes('/node_modules/')
) {
// Assert

@@ -152,0 +156,0 @@ return TRANSFORMER(context)(source);

@@ -23,5 +23,5 @@ import { Injectable, DependencyRegistry } from '@travetto/di';

await DependencyRegistry.init();
let item = await DependencyRegistry.getInstance(TestItem);
const item = await DependencyRegistry.getInstance(TestItem);
assert.strictEqual(item.getName(), 'Howdy');
}
}
import { Suite, Test, BeforeAll, AfterEach, AfterAll, BeforeEach } from '../';
import * as assert from 'assert';
let a: any = 0;
let a: any = 0; a = 2;

@@ -6,0 +6,0 @@ @Suite()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc