ember-qunit-codemod icon indicating copy to clipboard operation
ember-qunit-codemod copied to clipboard

Adding nested test failing testcase

Open alexander-alvarez opened this issue 8 years ago • 4 comments

alexander-alvarez avatar Nov 14 '17 00:11 alexander-alvarez

Hmm. I'm not quite sure how best to fix this. We intentionally only run on expressions in the root of the program body (so that we don't accidentally convert test() invocations that are not supposed to be transformed).

rwjblue avatar Nov 14 '17 00:11 rwjblue

Conceptually, could we not trace the lineage of the test function block in the AST to an allowed module, and use that to transform the test blocks?

alexander-alvarez avatar Nov 14 '17 01:11 alexander-alvarez

could we not trace the lineage of the test function block in the AST to an allowed module, and use that to transform the test blocks

I don't think we can know for certain 🤔

Consider this:

moduleForComponent('whatever', { integration: true });

// these should get transformed
test(...);
test(...);

export function generateTests() {
  // how do we attribute these?
  test(...);
  test(...);
  test(...);
}

rwjblue avatar Nov 14 '17 01:11 rwjblue

To be transformed generateTests would have to be invoked in the context of module?

// my-test-helper.js
export function generateTests() {
  test(...);
  test(...);
  test(...);
}
import { generateTests } from './my-test-helper';

moduleForComponent('whatever', { integration: true });

// these should get transformed
test(...);
test(...);

// I guess the original source would be transformed, and we hope that it's not used
// in another context too where we don't want it to be transformed?
generateTests();

Something like:

If program body is test-module, within the given module context inspect top-level (or nested) function invocations and see if they contain/are tests. If they do, then transform?

I'm not sure how much of this is possible / easy to do / etc, just shooting from the hip

alexander-alvarez avatar Nov 14 '17 01:11 alexander-alvarez