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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

grit-app[bot]
Copy link

@grit-app grit-app bot commented Feb 23, 2024

✅ 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)`
}

Tip

You can provide feedback to @gritagent and it will update this pull request with your suggestions.

<!-- grit:execution_id:a1b04dd3-6039-4eb8-998e-2828b4e5d475 -->
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.

0 participants