Skip to content

Commit

Permalink
chore(deps): bump chalk from ^1.1.3 to ^4.0.0 (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
aloisklink committed Sep 14, 2022
1 parent 52785d7 commit 916e76f
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 65 deletions.
54 changes: 13 additions & 41 deletions __tests__/index.spec.js
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,
},
});

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
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
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

0 comments on commit 916e76f

Please sign in to comment.