Giter VIP home page Giter VIP logo

Comments (9)

pmdartus avatar pmdartus commented on June 7, 2024 1

Jest sets by default process.env.NODE_ENV to `test: jest-runtime

We can rewrite registerComponent to:

export function registerComponent(tagName: string, Ctor: ComponentConstructor) {
    if (!isUndefined(TagNameToCtor[tagName])) {
        if (TagNameToCtor[tagName] === Ctor) {
            return;
        } else if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
            // TODO: eventually we should throw, this is only needed for the tests today
            assert.logWarning(`Different component class cannot be registered to the same tagName="${tagName}".`);
        }
    }
    TagNameToCtor[tagName] = Ctor;
}

from lwc.

caridy avatar caridy commented on June 7, 2024

Yeah, we need to spend time fixing all tests to either a) slice tests more so is easy to manage different tagNames in the same test, or b) use different tagName for each tests in every test file.

Part of that work is also to do the following for each tagName:

interface HTMLElementTagNameMap {
   'x-foo1': MyComponent1
}

which indicates to the type system that creation of such tags will be bound to that class definition, and this will remove many type errors in tests.

from lwc.

pmdartus avatar pmdartus commented on June 7, 2024

What about disabling the check in test mode ?

from lwc.

caridy avatar caridy commented on June 7, 2024

@pmdartus do we have such mode?

from lwc.

davidturissini avatar davidturissini commented on June 7, 2024

@pmdartus I thought that we talked about having multiple modes and it was a no-go because it would get complicated really quickly. I prefer the other approach of not recycling tag names because that matches more closely how LWC will be used, especially when customElements.register is used under the hood.

from lwc.

pmdartus avatar pmdartus commented on June 7, 2024

Then going down this route we need to be more restrictive and throw if 2 tests are using the same name. A warning is not enough the prevent new test to reuse existing names.

My main concern is that we will see an explosion of components with convoluted names, and I don't think it will be maintainable in the long run.

That being said we still have a couple of options to avoid adding another mode:

  • call jest.resetModules between each test to make sure we start again with a clean slate. It's something that I use in the performance timing tests to ensure to reset the uid between each test. One of the unpleasant side-effect of this approach is that it will slow down the test suite because it forces node re-evaluating the modules.
  • expose an internal flushRegistry method on def.ts and call it between each test. This method will get tree-shacked when bundling the engine.

After listing the different options we have, I still believe that using process.env.NODE_ENV is the simplest and most reliable approach. But it's my 2 cents comment.

from lwc.

davidturissini avatar davidturissini commented on June 7, 2024

@pmdartus Could we run the tests in production mode as opposed to dev mode?

from lwc.

pmdartus avatar pmdartus commented on June 7, 2024

Today the tests run in test mode. We don't do any special handling for this mode since we only check if production.

I think it's useful to run the tests in development to validate the assertions and warnings we put in place for development mode. But maybe it worth investigating running the tests also in production mode.


Edit:

React runs 4 suites of tests:

  • Test from source in development mode
  • Test from source in prod mode
  • Test from build artifact (react.js) in development mode
  • Test from build artifact (react.js) in prod mode

from lwc.

pmdartus avatar pmdartus commented on June 7, 2024

Here is branch with all the verbose unit test skipped: https://github.com/salesforce/lwc/compare/pmdartus/localize-all-warnings

That would be useful for the willing to tackle this issue.

from lwc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.