Skip to content

Commit

Permalink
Chore: fixes tests for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pustovitDmytro committed May 28, 2021
1 parent 1417972 commit d55d98f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bin/pack-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const COPY = [
const TEST_MODULES = [
'mocha',
'winston',
'uuid'
'winston-array-transport'
];

const resolveIgnoreRegexp = `^(?!${TEST_MODULES.join('|')}).*$`;
Expand Down
15 changes: 9 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"rollup": "^2.45.2",
"semantic-release": "^17.4.2",
"semantic-release-telegram": "^1.2.0",
"uuid": "^8.0.0"
"winston-array-transport": "^1.1.3"
},
"dependencies": {
"winston": "3.3.3"
Expand Down
16 changes: 8 additions & 8 deletions tests/package/configurations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ test('Positive: default configuration', async function () {
{ action: 'DELETE_POST', user: 'e595b156-f526-5b94-ab76-c9fb610e286b' }
];

const expected = `\
e3c0b365-26fd-54fc-afd7-d844c1d47a95;CREATE_POST
;UPDATE_POST
e3c0b365-26fd-54fc-afd7-d844c1d47a95;
;
e3c0b365-26fd-54fc-afd7-d844c1d47a95;
e595b156-f526-5b94-ab76-c9fb610e286b;DELETE_POST
`;
const expected = [
'e3c0b365-26fd-54fc-afd7-d844c1d47a95;CREATE_POST',
';UPDATE_POST',
'e3c0b365-26fd-54fc-afd7-d844c1d47a95;',
';',
'e3c0b365-26fd-54fc-afd7-d844c1d47a95;',
'e595b156-f526-5b94-ab76-c9fb610e286b;DELETE_POST'
];

await testFormatter(formatter, data, expected);
});
Expand Down
20 changes: 9 additions & 11 deletions tests/utils.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import path from 'path';
import { v4 as uuid } from 'uuid';
import fse from 'fs-extra';
import { assert } from 'chai';
import { createLogger, transports } from 'winston';
import { tmpFolder, entry } from './constants';
import ArrayTransport from 'winston-array-transport';
import { entry } from './constants';

export const pause = time => new Promise(res => setTimeout(res, time));

export async function testFormatter(formatter, data, expected) {
const fileId = uuid();
const filePath = path.join(tmpFolder, `formatter-${fileId}.csv`);
const logs = [];
const logger = createLogger({
level : 'info',
format : formatter,
transports : [
new transports.Console(),
new transports.File({
filename : filePath
new ArrayTransport({
array : logs
})
]
});

data.forEach(item => {
logger.log('info', item);
});
for (const line of expected) {
const logged = logs.shift();

await pause(1000);

const content = await fse.readFile(filePath);

assert.equal(content.toString(), expected);
assert.equal(logged, line);
}
}

export function load(relPath, clearCache) {
Expand Down

0 comments on commit d55d98f

Please sign in to comment.