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

Local helpers not resolved in tests #894

Closed
NullVoxPopuli opened this issue Jul 11, 2021 · 6 comments · Fixed by #953
Closed

Local helpers not resolved in tests #894

NullVoxPopuli opened this issue Jul 11, 2021 · 6 comments · Fixed by #953

Comments

@NullVoxPopuli
Copy link
Collaborator

Build Error (PackagerRunner) in tests/rendering/compile-hbs-test.ts

Module build failed (from ../../../../../home/me/Development/NullVoxPopuli/ember-play/node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 0)
$TMPDIR/embroider/5e47be/tests/dummy/tests/rendering/compile-hbs-test.ts/compile-hbs-test.ts: Missing helper: this.compile in tests/rendering/compile-hbs-test.ts

    at CompatResolver.dependenciesOf (/home/me/Development/NullVoxPopuli/ember-play/node_modules/@embroider/compat/src/resolver.js:251:33)
    at NodeTemplateCompiler.precompile (/home/me/Development/NullVoxPopuli/ember-play/node_modules/@embroider/core/src/template-compiler-common.js:78:42)
    at handleTagged (/home/me/Development/NullVoxPopuli/ember-play/node_modules/@embroider/core/src/babel-plugin-inline-hbs.js:68:62)
    at PluginPass.TaggedTemplateExpression (/home/me/Development/NullVoxPopuli/ember-play/node_modules/@embroider/core/src/babel-plugin-inline-hbs.js:38:29)
    at PluginPass.<anonymous> (/home/me/Development/NullVoxPopuli/ember-play/node_modules/@embroider/core/src/portable-babel-launcher.js:37:29)
    at newFn (/home/me/Development/NullVoxPopuli/ember-play/node_modules/@babel/traverse/lib/visitors.js:171:21)
    at NodePath._call (/home/me/Development/NullVoxPopuli/ember-play/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/home/me/Development/NullVoxPopuli/ember-play/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/home/me/Development/NullVoxPopuli/ember-play/node_modules/@babel/traverse/lib/path/context.js:90:31)
    at TraversalContext.visitQueue (/home/me/Development/NullVoxPopuli/ember-play/node_modules/@babel/traverse/lib/context.js:99:16)
  test('it works', async function (assert) {
    assert.expect(5);

    this.setProperties({
      compile: () => {
        let template = `
          {{#each (array 1 2) as |num|}}
            <output>{{num}}</output>
          {{/each}}
        `;

        let {component, name, error} = compileHBS(template);

        assert.notOk(error);
        assert.ok(name);

        return component;
      },
    });

    await render(
      hbs`
        {{#let (this.compile) as |CustomComponent|}}
          <CustomComponent />
        {{/let}}
      `
    );

    assert.dom('output').exists({count: 2});
    assert.dom().containsText('1');
    assert.dom().containsText('2');
  });

this occurs during the embroider-optimized build of my addon with the additional following config in the ember-cli-build:

  const { maybeEmbroider } = require('@embroider/test-setup');

  return maybeEmbroider(app, {
    packageRules: [
      {
        package: 'dummy',
        helpers: {
          '{{this.compile}}': { safeToIgnore: true },
        },
      },
    ],
    packagerOptions: {
      webpackConfig: {
        node: {
          global: false,
          __filename: true,
          __dirname: true,
        },
        resolve: {
          fallback: {
            path: 'path-browserify',
          },
        },
      },
    },
  });
@NullVoxPopuli
Copy link
Collaborator Author

I can kinda get past this with a non-ideal way via staticHelpers: false, but I don't think that's a great solution, as I do technically have a statically-analyzeable helper.

@lifeart
Copy link
Collaborator

lifeart commented Aug 6, 2021

looks like this in tests is a pain, in my understanding it should be runtime error (or wrapped with runtime assert), instead of build one

@ef4
Copy link
Contributor

ef4 commented Aug 6, 2021

The extra parentheses here mean you're trying to invoke this.compile as a helper:

{{#let (this.compile) as |CustomComponent|}}

I think it will work fine if you do this:

{{#let this.compile as |CustomComponent|}}

@NullVoxPopuli
Copy link
Collaborator Author

I have a plain-function helper-manager, so (this.compile) is correct

@lifeart
Copy link
Collaborator

lifeart commented Aug 27, 2021

error bubbling from

if (!this.staticHelpersEnabled) {

looks like resolver don't check JS/TS tokens around HBS templates (in general)

resolver.resolveSubExpression(node.path.original, filename, node.path.loc);

@lifeart
Copy link
Collaborator

lifeart commented Aug 27, 2021

@ef4 ef4 closed this as completed in #953 Aug 31, 2021
ef4 added a commit that referenced this issue Aug 31, 2021
…solved-in-tests

fixes: Local helpers not resolved in tests #894
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 a pull request may close this issue.

3 participants