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

contentful-batch-libs

Package Overview
Dependencies
Maintainers
3
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-batch-libs - npm Package Compare versions

Comparing version 9.4.1 to 9.4.2

11

dist/logging.js

@@ -137,5 +137,10 @@ "use strict";

if (errorLog.length) {
const warningsCount = errorLog.filter(error => Object.prototype.hasOwnProperty.call(error, 'warning')).length;
const errorsCount = errorLog.filter(error => Object.prototype.hasOwnProperty.call(error, 'warning')).length;
console.log(`\n\nThe following ${errorsCount} errors and ${warningsCount} warnings occurred:\n`);
const count = errorLog.reduce((count, curr) => {
if (Object.prototype.hasOwnProperty.call(curr, 'warning')) count.warnings++;else if (Object.prototype.hasOwnProperty.call(curr, 'error')) count.errors++;
return count;
}, {
warnings: 0,
errors: 0
});
console.log(`\n\nThe following ${count.errors} errors and ${count.warnings} warnings occurred:\n`);
errorLog.map(logMessage => `${(0, _format.default)((0, _parseISO.default)(logMessage.ts), 'HH:mm:ss')} - ${formatLogMessageOneLine(logMessage)}`).map(logMessage => console.log(logMessage));

@@ -142,0 +147,0 @@ return;

{
"name": "contentful-batch-libs",
"version": "9.4.1",
"version": "9.4.2",
"description": "Library modules used by contentful batch utility CLI tools.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

import { wrapTask } from '../lib'
import { logToTaskOutput, teardownHelperMock, formatLogMessageOneLine } from '../lib/logging'
import * as logging from '../lib/logging'
jest.mock('../lib/logging', () => {
const teardownHelperMock = jest.fn()
return {
formatLogMessageOneLine: jest.fn((logMessage) => `formatted: ${logMessage.error.message}`),
logToTaskOutput: jest.fn(() => {
return teardownHelperMock
}),
teardownHelperMock
}
jest.mock('../lib/logging')
const { logToTaskOutput, formatLogMessageOneLine } = logging
beforeEach(() => {
formatLogMessageOneLine.mockImplementation((logMessage) => `formatted: ${logMessage.error.message}`)
logToTaskOutput.mockImplementation(() => jest.fn())
})

@@ -17,7 +15,6 @@

logToTaskOutput.mockClear()
teardownHelperMock.mockClear()
formatLogMessageOneLine.mockClear()
})
test('wraps task, sets up listeners and allows modification of task context', () => {
test('wraps task, sets up listeners and allows modification of task context', async () => {
const ctx = {}

@@ -30,38 +27,35 @@

return wrappedTask(ctx)
.then(() => {
expect(ctx.done).toBe(true, 'context got modified by the task')
expect(logToTaskOutput.mock.calls).toHaveLength(1, 'task listener was initialized')
expect(teardownHelperMock.mock.calls).toHaveLength(1, 'task listener was teared down again')
expect(formatLogMessageOneLine.mock.calls).toHaveLength(0, 'no error was formatted')
})
await wrappedTask(ctx)
expect(ctx.done).toBe(true)
expect(logToTaskOutput.mock.calls).toHaveLength(1)
expect(formatLogMessageOneLine.mock.calls).toHaveLength(0)
})
test('wraps task and properly formats and throws error', async () => {
expect.assertions(9)
expect.assertions(7)
const ctx = {}
const errorMessage = 'Task failed'
const wrappedTask = wrapTask(() => {
return Promise.reject(new Error('Task failed'))
})
const wrappedTask = wrapTask(() => Promise.reject(new Error(errorMessage)))
let err
await wrappedTask(ctx)
.catch((error) => {
err = error
try {
await wrappedTask(ctx)
} catch (err) {
expect(err).toMatchObject({
message: `formatted: ${errorMessage}`,
originalError: {
message: errorMessage
}
})
}
expect(Object.keys(ctx)).toHaveLength(0, 'context got not modified by the task since it failed')
expect(err.message).toBe('formatted: Task failed', 'error message contains formatted error message')
expect(err.originalError.message).toBe('Task failed', 'original error message is still present')
expect(Object.keys(ctx)).toHaveLength(0)
expect(logToTaskOutput.mock.calls).toHaveLength(1)
expect(formatLogMessageOneLine.mock.calls).toHaveLength(1)
expect(logToTaskOutput.mock.calls).toHaveLength(1, 'task listener was initialized')
expect(teardownHelperMock.mock.calls).toHaveLength(1, 'task listener was teared down again')
expect(formatLogMessageOneLine.mock.calls).toHaveLength(1, 'error message was formatted')
expect(formatLogMessageOneLine.mock.calls[0][0].ts).not.toHaveLength(0, 'log message contains a timestamp')
expect(formatLogMessageOneLine.mock.calls[0][0].level).toBe('error', 'log message has level of error')
expect(formatLogMessageOneLine.mock.calls[0][0].error.message).toBe('Task failed', 'log message error has original error message')
expect(formatLogMessageOneLine.mock.calls[0][0].ts).not.toHaveLength(0)
expect(formatLogMessageOneLine.mock.calls[0][0].level).toBe('error')
expect(formatLogMessageOneLine.mock.calls[0][0].error.message).toBe(errorMessage)
})

@@ -135,8 +135,15 @@ import {

test('displays error log well formatted', () => {
displayErrorLog(exampleErrorLog)
const extendedExampleErrorLog = [...exampleErrorLog, {
ts: new Date('2022-01-01T01:05:43+01:00').toJSON(),
level: 'warning',
warning: 'another warning'
}]
expect(consoleLogSpy.mock.calls).toHaveLength(3)
expect(consoleLogSpy.mock.calls[0][0]).toContain('The following 1 errors and 1 warnings occurred:')
displayErrorLog(extendedExampleErrorLog)
expect(consoleLogSpy.mock.calls).toHaveLength(4)
expect(consoleLogSpy.mock.calls[0][0]).toContain('The following 1 errors and 2 warnings occurred:')
expect(consoleLogSpy.mock.calls[1][0]).toMatch(/\d{2}:\d{2}:\d{2} - warning text/)
expect(consoleLogSpy.mock.calls[2][0]).toMatch(/\d{2}:\d{2}:\d{2} - Error: error message/)
expect(consoleLogSpy.mock.calls[3][0]).toMatch(/\d{2}:\d{2}:\d{2} - another warning/)
})

@@ -151,20 +158,19 @@

test('writes error log file to disk', () => {
expect.assertions(7)
test('writes error log file to disk', async () => {
expect.assertions(8)
const destination = '/just/some/path/to/a/file.log'
return writeErrorLogFile(destination, exampleErrorLog)
.then(() => {
expect(consoleLogSpy.mock.calls).toHaveLength(2)
expect(consoleLogSpy.mock.calls[0][0]).toBe('\nStored the detailed error log file at:')
expect(consoleLogSpy.mock.calls[1][0]).toBe(destination)
await expect(writeErrorLogFile(destination, exampleErrorLog)).resolves.not.toThrow()
expect(bfj.write.mock.calls).toHaveLength(1)
expect(bfj.write.mock.calls[0][0]).toBe(destination)
expect(bfj.write.mock.calls[0][1]).toMatchObject(exampleErrorLog)
expect(bfj.write.mock.calls[0][2]).toMatchObject({
circular: 'ignore',
space: 2
})
})
expect(consoleLogSpy.mock.calls).toHaveLength(2)
expect(consoleLogSpy.mock.calls[0][0]).toBe('\nStored the detailed error log file at:')
expect(consoleLogSpy.mock.calls[1][0]).toBe(destination)
expect(bfj.write.mock.calls).toHaveLength(1)
expect(bfj.write.mock.calls[0][0]).toBe(destination)
expect(bfj.write.mock.calls[0][1]).toMatchObject(exampleErrorLog)
expect(bfj.write.mock.calls[0][2]).toMatchObject({
circular: 'ignore',
space: 2
})
})

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

expect(logEmitterEmitSpy.mock.calls[1][0]).toBe('display')
expect(isValidDate(logEmitterEmitSpy.mock.calls[1][1].ts)).toBe(true, 'attaches valid timestamp to log message')
expect(isValidDate(logEmitterEmitSpy.mock.calls[1][1].ts)).toBe(true)
expect(logEmitterEmitSpy.mock.calls[1][1].level).toBe('info')

@@ -209,3 +215,3 @@ expect(logEmitterEmitSpy.mock.calls[1][1].info).toBe('example info')

expect(logEmitterEmitSpy.mock.calls[1][0]).toBe('display')
expect(isValidDate(logEmitterEmitSpy.mock.calls[1][1].ts)).toBe(true, 'attaches valid timestamp to log message')
expect(isValidDate(logEmitterEmitSpy.mock.calls[1][1].ts)).toBe(true)
expect(logEmitterEmitSpy.mock.calls[1][1].level).toBe('warning')

@@ -217,3 +223,3 @@ expect(logEmitterEmitSpy.mock.calls[1][1].warning).toBe('example warning')

expect(logEmitterEmitSpy.mock.calls[1][0]).toBe('display')
expect(isValidDate(logEmitterEmitSpy.mock.calls[1][1].ts)).toBe(true, 'attaches valid timestamp to log message')
expect(isValidDate(logEmitterEmitSpy.mock.calls[1][1].ts)).toBe(true)
expect(logEmitterEmitSpy.mock.calls[1][1].level).toBe('error')

@@ -220,0 +226,0 @@ expect(logEmitterEmitSpy.mock.calls[1][1].error).toBe('example error')

@@ -0,1 +1,2 @@

import HttpsProxyAgent from 'https-proxy-agent'
import {

@@ -7,11 +8,3 @@ proxyStringToObject,

jest.mock('https-proxy-agent', () => {
const mock = jest.fn()
return class mocked {
constructor (args) {
this.mock = mock
mock(args)
}
}
})
jest.mock('https-proxy-agent')

@@ -134,3 +127,8 @@ test('proxyString with basic auth, with protocol', () => {

}
const agent = agentFromProxy(agentParams)
expect(agent).toBeInstanceOf(HttpsProxyAgent)
expect(HttpsProxyAgent.mock.calls[0][0]).toMatchObject(agentParams)
expect(process.env).not.toHaveProperty('HTTP_PROXY')

@@ -140,3 +138,2 @@ expect(process.env).not.toHaveProperty('http_proxy')

expect(process.env).not.toHaveProperty('https_proxy')
expect(agent.mock.mock.calls[0][0]).toMatchObject(agentParams)
})
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