Comments (9)
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.
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.
What about disabling the check in test mode ?
from lwc.
@pmdartus do we have such mode?
from lwc.
@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.
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 ondef.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.
@pmdartus Could we run the tests in production mode as opposed to dev mode?
from lwc.
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.
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)
- Label issues with package names HOT 4
- In dev mode, public APIs extending from superclasses may throw when called HOT 2
- Components that do not extend LightningElement should get dev warnings for missing `@api` HOT 3
- Components should not "inherit" `@api` from their superclasses HOT 1
- Add instrumentation/logging for native vs synthetic lifecycle callback differences HOT 1
- [ci] Firefox tests failing in SauceLabs
- DOMException: Failed to execute 'setAttributeNS' on 'Element' on `<svg xmlns:xlink>` HOT 3
- Unable to create hello world with LWC Open Source HOT 4
- Follow-up work for ElementInternals HOT 1
- `errorCallback` swallows SSR error HOT 2
- OpenTelemetry sdk for lwc HOT 4
- [3.7.0 regression] Re-rendering causes `this.refs.foo` to become `undefined` HOT 1
- [tests] `Unexpected attempt to set "disabled=true" property from the renderer`
- [Perf] Avoid calling `traverseAndSetElements` on every re-render
- [Template compiler] Event listeners on deep objects not being serialized properly HOT 2
- [Metadata] Inconsistency in AST for deep vs shallow expressions HOT 3
- Hydration does not support FACE or native lifecycle
- Simplify UpgradableConstructor use of native lifecycle callbacks
- Run Karma tests in CI in parallel
- Light Dom slots don't trigger `disconnectedCallback` in synthetic lifecycle HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lwc.