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

[bot] Run grit migration: Apply a GritQL pattern #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

grit-app[bot]
Copy link

@grit-app grit-app bot commented Dec 1, 2023

✅ This migration is up to date! ✅

⚠️ This pull request was auto-generated with Grit. ⚠️

This pull request was created with these settings:

  • Target branch: master
  • Source files: **/*
  • Preset pattern: chai_to_jest – Convert Chai test assertions to Jest.
Pattern body
engine marzano(0.1)
language js

pattern expect_like($o) {
    or {`expect($o)`, `expect($o).not`}
}

pattern have_like() {
    or { `have` , `has` }
}

pattern x_to($x) {
  or { `$x.to`, $x } where {
      $x <: expect_like($o)
  }
}

pattern include_like() {
    or { `include`, `includes`, `contain`, `contains` }
}

pattern x_to_be($x) {
  or {`$x.to.be`, `$x.to`, $x }
}

or {
    // pure chai -- assert
    `assert.match($s, $p, $_)` => `expect($s).toMatch($p)`,
    `assert.isFalse($x, $_)` => `expect($x).toBe(false)`,
    `assert.isTrue($x, $_)` => `expect($x).toBe(true)`,
    `assert.isNull($x, $_)` => `expect($x).toBe(null)`,
    `assert.toBe($x, $a, $_)` => `expect($x).toBe($a)`,
    `assert.isDefined($x, $_)` => `expect($x).toBeDefined()`,
    `assert.include($haystack, $needle, $_)` => `expect($haystack).toContain($needle)`,
    `assert.strictEqual($a, $b, $_)` => `expect($a).toBe($b)`,
    `assert.deepEqual($a, $b, $_)` => `expect($a).toEqual($b)`,
    `assert.equal($a, $b, $_)` => `expect($a).toEqual($b)`,
    `assert($x, $_)` =>  `expect($x).toBeTruthy()`,

    // equality
    `$xtobe.deep.equal($v)` where { $xtobe <: x_to_be($x) } => `$x.toEqual($v)`,
    `$xtobe.equal($v)` where { $xtobe <: x_to_be($x) } => `$x.toBe($v)`, // this is wrong in jest-codemods
    `$xtobe.equals($v)` where { $xtobe <: x_to_be($x) } => `$x.toBe($v)`,
    `$xtobe.eql($v)` where { $xtobe <: x_to_be($x) } => `$x.toEqual($v)`,
    `$xtobe.eq($v)` where { $xtobe <: x_to_be($x) } => `$x.toEqual($v)`,
    `$xtobe.greaterThan($n)` where { $xtobe <: x_to_be($x) } => `$x.toBeGreaterThan($n)`,
    `$xtobe.null` where { $xtobe <: x_to_be($x) } => `$x.toBeNull()`,
    `$xtobe.be($v)` where { $xtobe <: x_to_be($x) } => `$x.toBe($v)`, // leave it with .be to avoid false positives
    `$xtobe.true` where { $xtobe <: x_to_be($x) } => `$x.toBe(true)`,
    `$xtobe.false` where { $xtobe <: x_to_be($x) } => `$x.toBe(false)`,
    `$xtobe.exist` where { $xtobe <: x_to_be($x) }  => `$x.toEqual(expect.anything())`,
    `$xtobe.undefined` where { $xtobe <: x_to_be($x) } => `$x.toBeUndefined()`,
    `$xtobe.empty` where { $xtobe <: x_to_be($x) } => `$x.toHaveLength(0)`,
    `$xtobe.a('function')` where { $xtobe <: x_to_be($x) } => `$x.toBeInstanceOf(Function)`,
    `$xtobe.instanceOf($t)` where { $xtobe <: x_to_be($x) } => `$x.toBeInstanceOf($t)`,

    `$xtobe.object` where {
      $xtobe <: x_to_be($x),
      $x <: `expect($o)`
    } => `expect(typeof $o === 'object').toBeTruthy()`,

    `$xto.deep.$include($v, $_)` where { $xto <: x_to($x), $include <: include_like() }=> `$x.toMatchObject($v)`,
    `$xto.$include($e)` where { $xto <: x_to($x), $e <: object(), $include <: include_like() } => `$x.toMatchObject($e)`,
    `$xto.$include($e)` where { $xto <: x_to($x), $include <: include_like() } => `$x.toContain($e)`,

    `$xto.match($p, $_)` where { $xto <: x_to($x) } => `$x.toMatch($p)`, // leave it with to.match to avoid false positives

    `$xto.$h.length($n)` where { $xto <: x_to($x), $x <: have_like() } => `$x.toHaveLength($n)`,
    `$xto.$h.lengthOf($n)` where { $xto <: x_to($x), $x <: have_like() } => `$x.toHaveLength($n)`,
    `$xto.$h.property($p)` where { $xto <: x_to($x), $x <: have_like() } => `$x.toHaveProperty($p)`,
    `$xto.$h.keys($oneKey)` where {
      $xto <: x_to($x),
      $x <: have_like(),
      $oneKey <: not or { `[ $_ ]`, [ ... ] }
    } => `$x.toHaveProperty($oneKey)`
}

Please feel free to provide feedback on this pull request. Any comments will be incorporated into future migrations.

<!-- grit:execution_id:feb09721-7086-46c5-af58-5d31585bece4 -->
Copy link

@morgante morgante left a comment

Choose a reason for hiding this comment

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

@gritagent Always use toBe instead of toEqual.

@@ -33,7 +33,7 @@ describe('b2bOrder', () => {

createB2bOrder()(req, res, next)

expect(challenges.rceChallenge.solved).to.equal(true)
expect(challenges.rceChallenge.solved).toBe(true)

Choose a reason for hiding this comment

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

@gritagent Use toBeTruthy here.

Copy link

@morgante morgante Dec 11, 2023

Choose a reason for hiding this comment

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

@gritagent Use .not.toBeTruthy instead of toBe(false) in this file.

Copy link
Author

grit-app bot commented Dec 11, 2023

I have incorporated your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant