ember-codemods / ember-test-helpers-codemod

Codemod to transform your Ember tests to use @ember/test-helpers
MIT License
29 stars 14 forks source link

Transformation Error #29

Closed Yelinz closed 6 years ago

Yelinz commented 6 years ago

The Error occurred when running the codemod on ember 2.16.2 and 3.0.0

 ERR tests/integration/components/weekly-overview-day/component-test.js Transformation error
Error: Transformation attr.js errored on file tests/integration/components/weekly-overview-day/component-test.js. Reason TypeError: string.match is not a function or its return value is not iterable. Please report this in https://github.com/simonihmig/ember-test-helpers-codemod/issues

Stack trace:
TypeError: string.match is not a function or its return value is not iterable
    at migrateSelector (/home/user/.npm/_npx/10043/lib/node_modules/ember-test-helpers-codemod/lib/utils.js:131:39)
    at args.length.args.map.s (/home/user/.npm/_npx/10043/lib/node_modules/ember-test-helpers-codemod/lib/utils.js:154:42)
    at Array.map (<anonymous>)
    at createFindExpression (/home/user/.npm/_npx/10043/lib/node_modules/ember-test-helpers-codemod/lib/utils.js:154:33)
    at createAttributeExpression (/home/user/.npm/_npx/10043/lib/node_modules/ember-test-helpers-codemod/lib/transforms/integration/attr.js:16:7)
    at NodePath.root.find.filter.filter.replaceWith (/home/user/.npm/_npx/10043/lib/node_modules/ember-test-helpers-codemod/lib/transforms/integration/attr.js:73:32)
    at NodePath.<anonymous> (/home/user/.npm/_npx/10043/lib/node_modules/ember-test-helpers-codemod/node_modules/jscodeshift/src/collections/Node.js:144:47)
    at __paths.forEach (/home/user/.npm/_npx/10043/lib/node_modules/ember-test-helpers-codemod/node_modules/jscodeshift/src/Collection.js:76:36)
    at Array.forEach (<anonymous>)
    at Collection.forEach (/home/user/.npm/_npx/10043/lib/node_modules/ember-test-helpers-codemod/node_modules/jscodeshift/src/Collection.js:75:18)

Source:
import { expect } from 'chai'
import { describe, it } from 'mocha'
import { setupComponentTest } from 'ember-mocha'
import hbs from 'htmlbars-inline-precompile'
import moment from 'moment'

describe('Integration | Component | weekly overview day', function() {
  setupComponentTest('weekly-overview-day', {
    integration: true
  })

  it('renders', function() {
    this.set('day', moment({ y: 2017, m: 4, d: 5 }))
    this.set('expected', moment.duration({ h: 8 }))
    this.set('worktime', moment.duration({ h: 8 }))

    this.render(
      hbs`{{weekly-overview-day day=day expected=expected worktime=worktime}}`
    )

    expect(this.$()).to.have.length(1)

    expect(
      this.$('.day')
        .text()
        .trim()
    ).to.equal('05\n  Th')
  })

  it('computes a title', function() {
    this.set('day', moment({ y: 2017, m: 4, d: 5 }))
    this.set('expected', moment.duration({ h: 8, m: 30 }))
    this.set('worktime', moment.duration({ h: 8, m: 30 }))

    this.render(
      hbs`{{weekly-overview-day day=day expected=expected worktime=worktime prefix='Ferien'}}`
    )

    expect(this.$(':eq(0)').attr('title')).to.equal('Ferien, 8h 30m')
  })

  it('fires on-click action on click', function() {
    this.set('day', moment({ y: 2017, m: 4, d: 5 }))
    this.set('expected', moment.duration({ h: 8, m: 30 }))
    this.set('worktime', moment.duration({ h: 8, m: 30 }))
    this.set('clicked', false)

    this.render(
      hbs`{{weekly-overview-day day=day expected=expected worktime=worktime}}`
    )

    expect(this.get('clicked')).to.not.be.ok
    this.$('.bar').click()
    this.$('.day').click()
    expect(this.get('clicked')).to.not.be.ok

    this.render(
      hbs`{{weekly-overview-day day=day expected=expected worktime=worktime on-click=(action (mut clicked) true)}}`
    )

    expect(this.get('clicked')).to.not.be.ok

    this.$('.bar').click()

    expect(this.get('clicked')).to.be.ok

    this.set('clicked', false)

    expect(this.get('clicked')).to.not.be.ok

    this.$('.day').click()

    expect(this.get('clicked')).to.be.ok
  })
})

    at fs.readdirSync.forEach.fileName (/home/user/.npm/_npx/10043/lib/node_modules/ember-test-helpers-codemod/lib/presets/-preset.js:23:19)
    at Array.forEach (<anonymous>)
    at /home/user/.npm/_npx/10043/lib/node_modules/ember-test-helpers-codemod/lib/presets/-preset.js:15:8
    at module.exports (/home/user/.npm/_npx/10043/lib/node_modules/ember-test-helpers-codemod/index.js:18:14)
simonihmig commented 6 years ago

@Yelinz the problem was with this jQuery specific selector: :eq(0), without any normal selector (like .foo:eq(0)) the transform would fail. I skipped the transformation of these kind of selectors in #30, so the codemod does not break, but you would have to refactor these selector manually!

Yelinz commented 6 years ago

Thank you for the quick fix and response.