Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): bump chalk from ^1.1.3 to ^4.0.0 #310

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 13 additions & 41 deletions __tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ describe('toMatchImageSnapshot', () => {
runDiffImageToSnapshot: jest.fn(() => diffImageToSnapshotResult),
}));

jest.mock('supports-color', () => mockSupportsColor);
jest.mock('supports-color', () => ({
// 1 means basic ANSI 16-color support, 0 means no support
stdout: { level: mockSupportsColor ? 1 : 0 },
stderr: { level: mockSupportsColor ? 1 : 0 },
}));

const mockFs = Object.assign({}, fs, {
existsSync: jest.fn(),
Expand All @@ -36,12 +40,6 @@ describe('toMatchImageSnapshot', () => {
};
}

const ChalkMock = () => ({
bold: {
red: input => input,
},
});
Comment on lines -39 to -43
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to do anything, so I've removed it.
I'm guessing that maybe this code was used in earlier tests but is no longer needed.


beforeEach(() => {
// In tests, skip reporting (skip snapshotState update to not mess with our test report)
global.UNSTABLE_SKIP_REPORTING = true;
Expand Down Expand Up @@ -432,10 +430,8 @@ describe('toMatchImageSnapshot', () => {
runDiffImageToSnapshot,
}));

const Chalk = jest.fn();
jest.doMock('chalk', () => ({
constructor: Chalk,
}));
const Chalk = require('chalk').Instance;
jest.mock('chalk');
const { toMatchImageSnapshot } = require('../src/index');
const matcherAtTest = toMatchImageSnapshot.bind(mockTestContext);

Expand Down Expand Up @@ -478,10 +474,8 @@ describe('toMatchImageSnapshot', () => {
runDiffImageToSnapshot,
}));

const Chalk = jest.fn();
jest.doMock('chalk', () => ({
constructor: Chalk,
}));
const Chalk = require('chalk').Instance;
jest.mock('chalk');
const { configureToMatchImageSnapshot } = require('../src/index');
const customDiffConfig = { perceptual: true };
const customSnapshotIdentifier = ({ defaultIdentifier }) =>
Expand Down Expand Up @@ -526,7 +520,7 @@ describe('toMatchImageSnapshot', () => {
comparisonMethod,
});
expect(Chalk).toHaveBeenCalledWith({
enabled: false,
level: 0, // noColors
});
});

Expand All @@ -549,10 +543,8 @@ describe('toMatchImageSnapshot', () => {
diffImageToSnapshot,
}));

const Chalk = jest.fn();
jest.doMock('chalk', () => ({
constructor: Chalk,
}));
const Chalk = require('chalk').Instance;
jest.mock('chalk');
const { configureToMatchImageSnapshot } = require('../src/index');
const customConfig = { perceptual: true };
const toMatchImageSnapshot = configureToMatchImageSnapshot({
Expand Down Expand Up @@ -588,7 +580,7 @@ describe('toMatchImageSnapshot', () => {
comparisonMethod: 'pixelmatch',
});
expect(Chalk).toHaveBeenCalledWith({
enabled: false,
level: 0, // noColors
});
});

Expand Down Expand Up @@ -698,10 +690,6 @@ describe('toMatchImageSnapshot', () => {
const { toMatchImageSnapshot } = require('../src/index');
expect.extend({ toMatchImageSnapshot });

jest.doMock('chalk', () => ({
constructor: ChalkMock,
}));

expect(() => expect('pretendthisisanimagebuffer').toMatchImageSnapshot({ dumpDiffToConsole: true }))
.toThrowErrorMatchingSnapshot();
});
Expand All @@ -719,10 +707,6 @@ describe('toMatchImageSnapshot', () => {
const { toMatchImageSnapshot } = require('../src/index');
expect.extend({ toMatchImageSnapshot });

jest.doMock('chalk', () => ({
constructor: ChalkMock,
}));

expect(() => expect('pretendthisisanimagebuffer').toMatchImageSnapshot())
.toThrowErrorMatchingSnapshot();
});
Expand All @@ -745,10 +729,6 @@ describe('toMatchImageSnapshot', () => {
const { toMatchImageSnapshot } = require('../src/index');
expect.extend({ toMatchImageSnapshot });

jest.doMock('chalk', () => ({
constructor: ChalkMock,
}));

process.env.TERM_PROGRAM = 'xterm';

expect(() => expect('pretendthisisanimagebuffer').toMatchImageSnapshot({ dumpInlineDiffToConsole: true }))
Expand All @@ -771,10 +751,6 @@ describe('toMatchImageSnapshot', () => {
const { toMatchImageSnapshot } = require('../src/index');
expect.extend({ toMatchImageSnapshot });

jest.doMock('chalk', () => ({
constructor: ChalkMock,
}));

process.env.TERM_PROGRAM = 'iTerm.app';

expect(() => expect('pretendthisisanimagebuffer').toMatchImageSnapshot({ dumpInlineDiffToConsole: true }))
Expand All @@ -797,10 +773,6 @@ describe('toMatchImageSnapshot', () => {
const { toMatchImageSnapshot } = require('../src/index');
expect.extend({ toMatchImageSnapshot });

jest.doMock('chalk', () => ({
constructor: ChalkMock,
}));

process.env.ENABLE_INLINE_DIFF = true;

expect(() => expect('pretendthisisanimagebuffer').toMatchImageSnapshot({ dumpInlineDiffToConsole: true }))
Expand Down
96 changes: 75 additions & 21 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 @@ -60,7 +60,7 @@
"semantic-release": "^17.0.4"
},
"dependencies": {
"chalk": "^1.1.3",
"chalk": "^4.0.0",
"get-stdin": "^5.0.1",
"glur": "^1.1.2",
"lodash": "^4.17.4",
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
const kebabCase = require('lodash/kebabCase');
const merge = require('lodash/merge');
const path = require('path');
const Chalk = require('chalk').constructor;
const Chalk = require('chalk').Instance;
const { diffImageToSnapshot, runDiffImageToSnapshot } = require('./diff-snapshot');
const fs = require('fs');
const OutdatedSnapshotReporter = require('./outdated-snapshot-reporter');
Expand Down Expand Up @@ -174,7 +174,8 @@ function configureToMatchImageSnapshot({
} = this;
const chalkOptions = {};
if (typeof noColors !== 'undefined') {
chalkOptions.enabled = !noColors;
// 1 means basic ANSI 16-color support, 0 means no support
chalkOptions.level = noColors ? 0 : 1;
}
const chalk = new Chalk(chalkOptions);

Expand Down