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

More chai/sinon patches #315

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0417d3b
Make sinon.stub() mock implementation when nothing is returned (& oth…
danbeam Jun 9, 2022
54a7fdf
Bump version to 0.26.2
skovhus Jun 9, 2022
bb90ed5
Downgrade globby/execa to fix ESM issue (#293)
skovhus Jun 10, 2022
42aa9ae
Enable auto merge of minor Renovate updates (#294)
skovhus Jun 10, 2022
1cc4f8a
Make git tag after release
skovhus Jun 10, 2022
3279caa
Update babel monorepo to v7.18.2
renovate-bot Jun 10, 2022
12d297d
Update dependency ts-jest to v28.0.4
renovate-bot Jun 10, 2022
22f5140
Update jest monorepo
renovate-bot Jun 10, 2022
f16ea9a
Update Node.js to v18.3.0
renovate-bot Jun 10, 2022
5ed3d41
Update dependency eslint to v8.17.0
renovate-bot Jun 10, 2022
c3331e0
Update dependency eslint-plugin-jest to v26.5.3
renovate-bot Jun 10, 2022
9a57e2d
Update dependency lint-staged to v12.5.0
renovate-bot Jun 10, 2022
87eb84d
Update dependency typescript to v4.7.3
renovate-bot Jun 10, 2022
63437bb
Update typescript-eslint monorepo to v5.27.1
renovate-bot Jun 11, 2022
6513f2d
Update dependency @babel/core to v7.18.5
renovate-bot Jun 13, 2022
2722388
Update typescript-eslint monorepo to v5.28.0
renovate-bot Jun 13, 2022
52b7114
Update dependency ts-jest to v28.0.5
renovate-bot Jun 13, 2022
ad5ce51
Update dependency prettier to v2.7.0
renovate-bot Jun 14, 2022
ff32cce
Update dependency lint-staged to v13 (#287)
renovate[bot] Jun 15, 2022
33f2c50
Update dependency @types/jest to v28 (#289)
renovate[bot] Jun 15, 2022
6387b43
Update dependency prettier to v2.7.1
renovate-bot Jun 16, 2022
75612a8
Update Node.js to v18.4.0
renovate-bot Jun 16, 2022
b67412d
Update dependency lint-staged to v13.0.2
renovate-bot Jun 16, 2022
34a9e28
Update dependency @types/jest to v28.1.2
renovate[bot] Jun 17, 2022
017efb1
Update dependency typescript to v4.7.4
renovate[bot] Jun 17, 2022
957d496
Update dependency eslint to v8.18.0
renovate[bot] Jun 17, 2022
34f64cc
Update typescript-eslint monorepo to v5.29.0
renovate[bot] Jun 20, 2022
d8d896a
Update dependency @types/jest to v28.1.3
renovate[bot] Jun 21, 2022
c3f6e99
Update dependency lint-staged to v13.0.3
renovate[bot] Jun 24, 2022
cb6e1b2
Update dependency eslint-plugin-prettier to v4.1.0
renovate[bot] Jun 27, 2022
f63358e
Update typescript-eslint monorepo to v5.30.0
renovate[bot] Jun 27, 2022
cbf40bd
Update babel monorepo to v7.18.6
renovate[bot] Jun 27, 2022
0cce9e9
Update dependency jest to v28.1.2
renovate[bot] Jun 29, 2022
314ab45
Subtle equality
danbeam Jun 6, 2022
b4a183f
More chai tweaks
catc Jun 27, 2022
e37e886
Only add `as jest.Mock` if `spyOn()` not present
danbeam Jun 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2

defaults: &defaults
docker:
- image: cimg/node:18.2.0
- image: cimg/node:18.4.0

_steps:
save_npm_cache: &save_npm_cache
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-codemods",
"version": "0.26.1",
"version": "0.26.3",
"description": "Codemods for migrating test files to Jest",
"license": "MIT",
"repository": "skovhus/jest-codemods",
Expand All @@ -26,7 +26,7 @@
"test:cov": "yarn test --coverage",
"test:watch": "yarn test --watch",
"test": "jest --runInBand",
"verify": "yarn lint && yarn build && yarn test:cov",
"verify": "yarn lint && yarn build && ./bin/jest-codemods.js --version && yarn test:cov",
"verify:bail": "yarn lint:bail && yarn verify",
"ci": "yarn verify:bail && codecov",
"prepare": "husky install"
Expand All @@ -53,35 +53,35 @@
"codemods"
],
"dependencies": {
"@babel/core": "7.18.0",
"@babel/preset-env": "7.18.0",
"@babel/core": "7.18.6",
"@babel/preset-env": "7.18.6",
"chalk": "4.1.2",
"execa": "6.1.0",
"globby": "13.1.1",
"execa": "4.1.0",
"globby": "11.1.0",
"inquirer": "8.2.4",
"is-git-clean": "1.1.0",
"jscodeshift": "0.13.1",
"meow": "7.1.1",
"update-notifier": "5.1.0"
},
"devDependencies": {
"@types/jest": "27.5.1",
"@types/jest": "28.1.3",
"@types/jscodeshift": "0.11.5",
"@types/update-notifier": "5.1.0",
"@typescript-eslint/eslint-plugin": "5.23.0",
"@typescript-eslint/parser": "5.23.0",
"@typescript-eslint/eslint-plugin": "5.30.0",
"@typescript-eslint/parser": "5.30.0",
"codecov": "3.8.3",
"eslint": "8.16.0",
"eslint": "8.18.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-jest": "26.4.2",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-jest": "26.5.3",
"eslint-plugin-prettier": "4.1.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"husky": "8.0.1",
"jest": "28.1.0",
"lint-staged": "12.4.1",
"prettier": "2.6.2",
"ts-jest": "28.0.2",
"typescript": "4.6.4"
"jest": "28.1.2",
"lint-staged": "13.0.3",
"prettier": "2.7.1",
"ts-jest": "28.0.5",
"typescript": "4.7.4"
},
"jest": {
"preset": "ts-jest",
Expand Down
4 changes: 4 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ fi
echo "Deploying version $version."

yarn publish

tag=$version
git tag -a "${tag}" -m "Release ${tag}"
git push origin "${tag}"
8 changes: 6 additions & 2 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": [
"config:base"
"extends": ["config:base"],
"packageRules": [
{
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
"automerge": true
}
]
}
4 changes: 2 additions & 2 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import chalk from 'chalk'
import { globbySync } from 'globby'
import globby from 'globby'
import inquirer from 'inquirer'
import meow from 'meow'
import updateNotifier from 'update-notifier'
Expand Down Expand Up @@ -157,7 +157,7 @@ function supportFailure(supportedItems) {

function expandFilePathsIfNeeded(filesBeforeExpansion) {
const shouldExpandFiles = filesBeforeExpansion.some((file) => file.includes('*'))
return shouldExpandFiles ? globbySync(filesBeforeExpansion) : filesBeforeExpansion
return shouldExpandFiles ? globby.sync(filesBeforeExpansion) : filesBeforeExpansion
}

inquirer
Expand Down
2 changes: 1 addition & 1 deletion src/cli/transformers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

let execaReturnValue
jest.setMock('execa', {
execaSync: () => execaReturnValue,
sync: () => execaReturnValue,
})

import fs from 'fs'
Expand Down
4 changes: 2 additions & 2 deletions src/cli/transformers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execaSync } from 'execa'
import execa from 'execa'
import path from 'path'

export const transformerDirectory = path.join(__dirname, '../', 'transformers')
Expand Down Expand Up @@ -50,7 +50,7 @@ function executeTransformation({

console.log(`Executing command: jscodeshift ${args.join(' ')}`)

const result = execaSync('node', [jscodeshiftExecutable, ...args], {
const result = execa.sync('node', [jscodeshiftExecutable, ...args], {
stdio: 'inherit',
stripFinalNewline: false,
})
Expand Down
123 changes: 100 additions & 23 deletions src/transformers/chai-should.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test('chai-enzyme: handle .to.contain(JSXElement)', () => {
expect(wrapper).to.contain(<ImpressionLogger />)
`,
`
expect(wrapper.contains(<ImpressionLogger />)).toEqual(true)
expect(wrapper).containsMatchingElement(<ImpressionLogger />)
`
)
})
Expand Down Expand Up @@ -120,8 +120,8 @@ test('removes imports and does basic conversions of should and expect', () => {
`
describe('Instantiating TextField', () => {
it('should set the placeholder correctly', () => {
expect(textField.props.placeholder).toEqual(PLACEHOLDER);
expect(textField.props.placeholder).not.toEqual(PLACEHOLDER);
expect(textField.props.placeholder).toBe(PLACEHOLDER);
expect(textField.props.placeholder).not.toBe(PLACEHOLDER);
});
});
`
Expand Down Expand Up @@ -156,13 +156,13 @@ test('removes imports and does basic conversions of should and expect (2)', () =
`
describe('Instantiating TextField', () => {
it('should set the placeholder correctly', () => {
expect(textField.props.placeholder).toEqual(PLACEHOLDER);
expect(textField.props.placeholder).not.toEqual(PLACEHOLDER);
expect(textField.props.placeholder).toBe(PLACEHOLDER);
expect(textField.props.placeholder).not.toBe(PLACEHOLDER);
});

it('should inherit id prop', () => {
expect(dropdown.props.id).toEqual(STANDARD_PROPS.id);
expect(dropdown.props.id).not.toEqual(STANDARD_PROPS.id);
expect(dropdown.props.id).toBe(STANDARD_PROPS.id);
expect(dropdown.props.id).not.toBe(STANDARD_PROPS.id);
});

it('should map open prop to visible prop', () => {
Expand Down Expand Up @@ -190,8 +190,8 @@ test('removes imports (case where should is not assigned)', () => {
`
describe('Instantiating TextField', () => {
it('should set the placeholder correctly', () => {
expect(textField.props.placeholder).toEqual(PLACEHOLDER);
expect(textField.props.placeholder).not.toEqual(PLACEHOLDER);
expect(textField.props.placeholder).toBe(PLACEHOLDER);
expect(textField.props.placeholder).not.toBe(PLACEHOLDER);
});
});`
)
Expand Down Expand Up @@ -456,22 +456,28 @@ test('converts "equal"', () => {
expect(42).to.equal(42);
expect(1).to.not.equal(true);
expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });

expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
expect({ foo: 'bar' }).not.to.deep.equal({ foo: 'bar' });
expect({ foo: 'bar' }).to.not.deep.equal({ foo: 'bar' });

should.equal('foo', 'foo');
should.not.equal('foo', 'bar');
`,
`
expect('hello').toEqual('hello');
expect('hello').toBe('hello');
// some message here explaining hello
expect('hello').toEqual('hello');
expect(42).toEqual(42);
expect(1).not.toEqual(true);
expect({ foo: 'bar' }).not.toEqual({ foo: 'bar' });
expect('hello').toBe('hello');
expect(42).toBe(42);
expect(1).not.toBe(true);
expect({ foo: 'bar' }).not.toBe({ foo: 'bar' });

expect({ foo: 'bar' }).toEqual({ foo: 'bar' });
expect({ foo: 'bar' }).not.toEqual({ foo: 'bar' });
expect({ foo: 'bar' }).not.toEqual({ foo: 'bar' });

expect('foo').toEqual('foo');
expect('foo').not.toEqual('bar');
expect('foo').toBe('foo');
expect('foo').not.toBe('bar');
`
)
})
Expand Down Expand Up @@ -633,6 +639,17 @@ test('converts chained "includes-contains"', () => {
)
})

test('chai-enzyme: handle .text() with .contains()', () => {
expectTransformation(
`
expect(wrapper.text()).to.contain(priceString);
`,
`
expect(wrapper.text()).toContain(priceString);
`
)
})

test('converts empty array assertion', () => {
expectTransformation(
`
Expand Down Expand Up @@ -1030,11 +1047,11 @@ test('removes params to expect() except for the first', () => {
// Expected foo to be defined
expect(foo).toBeDefined();
// Expected foo to be defined
expect(foo).toEqual(true);
expect(foo).toBe(true);
// Expected foo to be defined for \${id}
expect(foo).toBeDefined();
// 'Expected ' + foo + ' to be defined'
expect(foo).toEqual(true);
expect(foo).toBe(true);
`
)
})
Expand Down Expand Up @@ -1118,6 +1135,47 @@ test('converts equalto(null) to toBeNull()', () => {
)
})

test('converts subtly different equality operators', () => {
expectTransformation(
`
// Strict equality (===)
expect(2 + 2).to.eq(5);
expect(2 + 2).to.equal(5);
expect(2 + 2).to.equals(5);
expect(2 + 2).to.not.equals(5);
expect(2 + 2).not.to.equals(5);

// Strict equality (===) + deep = deep equality
expect(2 + 2).to.deep.eq(5);

// Deep equality
expect(2 + 2).to.eql(5);
expect(2 + 2).to.eqls(5);
expect(2 + 2).to.not.eqls(5);
expect(2 + 2).not.to.eqls(5);
expect(2 + 2).to.deep.eql(5);
`,
`
// Strict equality (===)
expect(2 + 2).toBe(5);
expect(2 + 2).toBe(5);
expect(2 + 2).toBe(5);
expect(2 + 2).not.toBe(5);
expect(2 + 2).not.toBe(5);

// Strict equality (===) + deep = deep equality
expect(2 + 2).toEqual(5);

// Deep equality
expect(2 + 2).toEqual(5);
expect(2 + 2).toEqual(5);
expect(2 + 2).not.toEqual(5);
expect(2 + 2).not.toEqual(5);
expect(2 + 2).toEqual(5);
`
)
})

test('converts "within"', () => {
expectTransformation(
`
Expand Down Expand Up @@ -1219,9 +1277,10 @@ it('leaves code without should/expect', () => {
expect(result).toBeNull()
})

it('converts before, after and context to beforeAll, afterAll and describe', () => {
expectTransformation(
`
describe('converts before, after and context to beforeAll, afterAll and describe', () => {
it('converts cases correctly', () => {
expectTransformation(
`
before(() => {
doSetup();
});
Expand All @@ -1238,7 +1297,7 @@ it('converts before, after and context to beforeAll, afterAll and describe', ()
});
});
`,
`
`
beforeAll(() => {
doSetup();
});
Expand All @@ -1255,7 +1314,25 @@ it('converts before, after and context to beforeAll, afterAll and describe', ()
});
});
`
)
)
})

it('skips call expression spreads with the same identifier', () => {
expectTransformation(
`
const foo = {
a: 'aa',
...context(searchParams),
}
`,
`
const foo = {
a: 'aa',
...context(searchParams),
}
`
)
})
})

test('supports chai-arrays plugin', () => {
Expand Down
Loading