ember-intl / cp-validations

ember-intl support for ember-cp-validations
MIT License
10 stars 13 forks source link

Enable embroider-optimized scenario #92

Open fsmanuel opened 2 years ago

fsmanuel commented 2 years ago

The embroider-optimized scenario tests fail with the following errors:

 not ok 6 Chrome 105.0 - [15 ms] - Unit | Validators | messages: it exists
    ---
        expected: >
            true
        stack: >
                at Object.eval (webpack://dummy/./tests/unit/validators/messages-test.js?:14:12)
        message: >
            failed, expected argument to be truthy, was: undefined
        negative: >
            false
        browser log: |
    ...
not ok 7 Chrome 105.0 - [35 ms] - Unit | Validators | messages: suppressWarnings set to true
    ---
        actual: >
            null
        stack: >
            TypeError: Cannot read properties of undefined (reading 'getMessageFor')
                at Object.eval (webpack://dummy/./tests/unit/validators/messages-test.js?:25:14)
        message: >
            Died on test #1: Cannot read properties of undefined (reading 'getMessageFor')
                at Object.eval (webpack://dummy/./tests/unit/validators/messages-test.js?:16:46)
        negative: >
            false
        browser log: |
    ...
not ok 8 Chrome 105.0 - [18 ms] - Unit | Validators | messages: suppressWarnings unset
    ---
        actual: >
            null
        stack: >
            TypeError: Cannot read properties of undefined (reading 'getMessageFor')
                at Object.eval (webpack://dummy/./tests/unit/validators/messages-test.js?:32:14)
        message: >
            Died on test #1: Cannot read properties of undefined (reading 'getMessageFor')
                at Object.eval (webpack://dummy/./tests/unit/validators/messages-test.js?:28:46)
        negative: >
            false
        browser log: |
    ...

Seems like instance is undefined inembroider-optimized scenario.

const specifier = '@ember-intl/cp-validations@validator:messages';
const instance = this.owner.lookup(specifier);
instance.getMessageFor('foobarbaz');
fsmanuel commented 2 years ago

From the discussion https://github.com/ember-intl/cp-validations/pull/90#discussion_r975732239

function embroiderOptimized(extension) {
    return extendScenario({
        name: 'embroider-optimized',
        npm: {
            devDependencies: {
                '@embroider/core': currentEmbroiderVersion,
                '@embroider/webpack': currentEmbroiderVersion,
                '@embroider/compat': currentEmbroiderVersion,
                // Webpack is a peer dependency of `@embroider/webpack`
                webpack: '^5.0.0',
            },
        },
        env: {
            EMBROIDER_TEST_SETUP_OPTIONS: 'optimized',
        },
    }, extension);
}

I think ember-auto-import v2 is present via @embroider/util which has "ember-auto-import": "^2.2.0", as a dependency. Also the embroider-safe scenario works which has the same devDependencies as embroiderOptimized from above.

$ npm ls @embroider/util
@ember-intl/cp-validations@5.0.0 /Users/manuel/Code/opensource/cp-validations
└─┬ @ember/test-helpers@2.8.1
  └── @embroider/util@1.8.3