Skip to content

Commit

Permalink
test: refactor ConsoleLogRecordExporter assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
10xLaCroixDrinker committed Mar 11, 2024
1 parent 381faa2 commit 24a025c
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ describe('ConsoleLogRecordExporter', () => {
severityNumber: SeverityNumber.DEBUG,
severityText: 'DEBUG',
});
const consoleOutput = stdoutStub.getCalls()[0].firstArg;
stdoutStub.restore();

const logRecords = spyExport.args[0];
const firstLogRecord = logRecords[0][0];
const consoleArgs = consoleSpy.args[0];
const consoleLogRecord = consoleArgs[0];
const consoleDirOpts = consoleArgs[1];
const keys = Object.keys(consoleLogRecord).sort().join(',');
consoleSpy.restore();

Expand All @@ -69,15 +69,8 @@ describe('ConsoleLogRecordExporter', () => {
assert.equal(firstLogRecord.severityNumber, SeverityNumber.DEBUG);
assert.equal(firstLogRecord.severityText, 'DEBUG');
assert.equal(keys, expectedKeys);

assert.equal(consoleDirOpts.colors, undefined);

Check failure on line 72 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / build

Object is possibly 'undefined'.

Check failure on line 72 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Object is possibly 'undefined'.

Check failure on line 72 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (14)

Object is possibly 'undefined'.

Check failure on line 72 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (16)

Object is possibly 'undefined'.

Check failure on line 72 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Object is possibly 'undefined'.

Check failure on line 72 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Object is possibly 'undefined'.

Check failure on line 72 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Object is possibly 'undefined'.

Check failure on line 72 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Object is possibly 'undefined'.
assert.ok(spyExport.calledOnce);

const containsColor = isColorText(consoleOutput);
assert.equal(
containsColor,
(process.env.FORCE_COLOR && process.env.FORCE_COLOR !== '0') ||
process.stdout.isTTY
);
});
it('should colorize log records', () => {
const consoleExporter = new ConsoleLogRecordExporter({ colors: true });
Expand All @@ -86,15 +79,19 @@ describe('ConsoleLogRecordExporter', () => {
new SimpleLogRecordProcessor(consoleExporter)
);

const consoleSpy = sinon.spy(console, 'dir');
const stdoutStub = sinon.stub(process.stdout, 'write');
provider.getLogger('default').emit({
body: 'body2',
severityNumber: SeverityNumber.DEBUG,
severityText: 'DEBUG',
});
const consoleOutput = stdoutStub.getCalls()[0].firstArg;
const consoleDirOpts = consoleSpy.args[0][1];
stdoutStub.restore();
consoleSpy.restore();

assert.equal(consoleDirOpts.colors, true);

Check failure on line 94 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / build

Object is possibly 'undefined'.

Check failure on line 94 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Object is possibly 'undefined'.

Check failure on line 94 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (14)

Object is possibly 'undefined'.

Check failure on line 94 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (16)

Object is possibly 'undefined'.

Check failure on line 94 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Object is possibly 'undefined'.

Check failure on line 94 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Object is possibly 'undefined'.

Check failure on line 94 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Object is possibly 'undefined'.

Check failure on line 94 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Object is possibly 'undefined'.
const containsColor = isColorText(consoleOutput);
assert.ok(containsColor);
});
Expand All @@ -105,15 +102,19 @@ describe('ConsoleLogRecordExporter', () => {
new SimpleLogRecordProcessor(consoleExporter)
);

const consoleSpy = sinon.spy(console, 'dir');
const stdoutStub = sinon.stub(process.stdout, 'write');
provider.getLogger('default').emit({
body: 'body3',
severityNumber: SeverityNumber.DEBUG,
severityText: 'DEBUG',
});
const consoleOutput = stdoutStub.getCalls()[0].firstArg;
const consoleDirOpts = consoleSpy.args[0][1];
stdoutStub.restore();
consoleSpy.restore();

assert.equal(consoleDirOpts.colors, false);

Check failure on line 117 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / build

Object is possibly 'undefined'.

Check failure on line 117 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / browser-tests

Object is possibly 'undefined'.

Check failure on line 117 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (14)

Object is possibly 'undefined'.

Check failure on line 117 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (16)

Object is possibly 'undefined'.

Check failure on line 117 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-windows-tests

Object is possibly 'undefined'.

Check failure on line 117 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (18)

Object is possibly 'undefined'.

Check failure on line 117 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / node-tests (20)

Object is possibly 'undefined'.

Check failure on line 117 in experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts

View workflow job for this annotation

GitHub Actions / webworker-tests

Object is possibly 'undefined'.
const doesNotContainColor = !isColorText(consoleOutput);
assert.ok(doesNotContainColor);
});
Expand Down

0 comments on commit 24a025c

Please sign in to comment.