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

Unify internal testing styles #15988

Closed
13 of 14 tasks
thoov opened this issue Dec 15, 2017 · 20 comments
Closed
13 of 14 tasks

Unify internal testing styles #15988

thoov opened this issue Dec 15, 2017 · 20 comments

Comments

@thoov
Copy link
Member

thoov commented Dec 15, 2017

Currently there are two different styles that tests are written. An older style which uses a QUnit global to define the module and tests via QUnit.module() and QUnit.test(). The old style also uses globals for the assertion such as ok, equal, etc. A newer style which does not use QUnit globals is partially rolled out in some of the packages. This issue tracks the work needed to move all tests over to the newer style and the related work surrounding it.

A breakdown of how to complete the conversion:

  1. QUnit.module becomes moduleFor
// Old Style:
QUnit.module('<MODULE_NAME>');

// New Style:
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

moduleFor('<MODULE_NAME>', class extends AbstractTestCase {
  //...
});

Note: There are a few test case classes already so check here for other options.

  1. QUnit.test becomes a property on the test case class
// Old Style:
QUnit.test('<TEST_NAME>', function() {
  // test case here
});

// New Style:
moduleFor('<MODULE_NAME>', class extends TestCase {
  ['@test <TEST_NAME>'](assert) {
    // test case here
  }
});
  1. Assertions should be references off of the callback assert argument
// Bad:
QUnit.test('<TEST_NAME>', function() {
  equal(1, 1);
});

// Bad:
moduleFor('<MODULE_NAME>', class extends TestCase {
  ['@test <TEST_NAME>']() {
    this.assert.equal(1, 1);
  }
});

// Good:
moduleFor('<MODULE_NAME>', class extends TestCase {
  ['@test <TEST_NAME>'](assert) {
    assert.equal(1,1)
  }
});

Below are the packages that need to be converted:

Below is the test related cleanup that is needed:

@thoov thoov changed the title Unify testing strategies Unify testing styles Dec 15, 2017
@thoov thoov changed the title Unify testing styles Unify internal testing styles Dec 15, 2017
@rwjblue
Copy link
Member

rwjblue commented Dec 15, 2017

Thanks for putting this together @thoov!

@locks
Copy link
Contributor

locks commented Dec 15, 2017

I have taken ember-application, ember-debug, and ember-utils: #15986.

@t-sauer
Copy link
Contributor

t-sauer commented Dec 15, 2017

I will take a stab at container.

@karthiicksiva
Copy link
Contributor

I will take the ember-template-compiler

@mikerhyssmith
Copy link
Contributor

Happy to take a stab at runtime!

@cibernox
Copy link
Contributor

I can take ember-testing

@locks
Copy link
Contributor

locks commented Dec 22, 2017

Took part of ember: #16019.

@Turbo87
Copy link
Member

Turbo87 commented Dec 30, 2017

Can anyone tell me the advantages of the new testing API given that for Ember projects we're now explicitly moving away from moduleFor? 🤔

@rwjblue
Copy link
Member

rwjblue commented Dec 30, 2017

The moduleFor being used here is completely unrelated to the legacy moduleFor implementation that is provided by ember-qunit.

cibernox added a commit to cibernox/ember.js that referenced this issue Dec 30, 2017
@Turbo87
Copy link
Member

Turbo87 commented Dec 31, 2017

@rwjblue I'm aware of that, but it seems that the same pros and cons apply and I'm wondering why this decision was made

@thoov
Copy link
Member Author

thoov commented Jan 11, 2018

@mikerhyssmith For packages/ember-runtime/tests/suites:

It currently has a concept called SuiteBuilder that needs to be converted to the newer AbstractTestCase model.

// BEFORE
const suite = SuiteModuleBuilder.create();

suite.module('includes');

suite.test('includes returns correct value if startAt is positive', function(assert) {
  let data = this.newFixture(3);
  let obj  = this.newObject(data);

  assert.equal(obj.includes(data[1], 1), true, 'should return true if included');
  assert.equal(obj.includes(data[0], 1), false, 'should return false if not included');
});
// AFTER (this class should go in `internal-test-helpers/lib/test-cases)`
class RuntimeTestCase extends AbstractTestCase {
  newFixture() {
    // ...
  }

  newObject() {
    // ...
  }

  // ...
}
// now you can convert the tests pretty much one to one
moduleFor('includes', class extends RuntimeTestCase {
  ['@test includes returns correct value if startAt is positive', function(assert) {
    let data = this.newFixture(3);
    let obj  = this.newObject(data);

    assert.equal(obj.includes(data[1], 1), true, 'should return true if included');
    assert.equal(obj.includes(data[0], 1), false, 'should return false if not included');
  }
});

Let me know if you need any help with this or anything in packages/ember-runtime

@mikerhyssmith
Copy link
Contributor

@thoov thanks ! I noticed a fair few of the remaining tests have testBoth in and some work has been done in the ember-metal tests to support that. Do I need to wait for that to go in first ?

@thoov
Copy link
Member Author

thoov commented Jan 11, 2018

@michaelklishin We are moving away from testBoth as under the hood it is just converting it to this (https://github.com/emberjs/ember.js/blob/master/packages/internal-test-helpers/lib/test-groups.js#L15-L25) however in the second QUnit test it references USES_ACCESSORS which is never set and therefore it just does assert.ok('SKIPPING ACCESSORS'); which isn't useful. Originally we were going to support both cases (which is probably what you saw) but realized that we could just kill that one off. Here is a PR I recently did that moved away from testBoth (https://github.com/emberjs/ember.js/pull/16072/files) that you can use as a guide and let me know if you need help with anything.

lorcan pushed a commit to lorcan/ember.js that referenced this issue Feb 6, 2018
thoov added a commit to thoov/ember.js that referenced this issue Mar 16, 2018
thoov added a commit to thoov/ember.js that referenced this issue Mar 29, 2018
thoov added a commit to thoov/ember.js that referenced this issue Mar 29, 2018
thoov added a commit to thoov/ember.js that referenced this issue Mar 29, 2018
thoov added a commit to thoov/ember.js that referenced this issue Apr 1, 2018
thoov added a commit to thoov/ember.js that referenced this issue Apr 1, 2018
thoov added a commit to thoov/ember.js that referenced this issue Apr 3, 2018
Moving off of the QUnit global by refactoring away from
QUnit.config.current.assert.

Apart of emberjs#15988
thoov added a commit to thoov/ember.js that referenced this issue Apr 4, 2018
Refactoring away from direct QUnit.module and QUnit.test usage.

Apart of emberjs#15988
thoov added a commit to thoov/ember.js that referenced this issue Jul 11, 2018
Moving off of QUnit.config.current in array helpers. Apart of emberjs#15988
lifeart added a commit to lifeart/ember.js that referenced this issue Jul 13, 2018
* Add eslint-plugin-import to validate imports.

This ensures that all imports are resolvable and valid.

Future changes should enable more rules from eslint-plugin-import (such
as ensuring that a given imported module is only specified once or
preventing module cycles).

* Add test for issue emberjs#16427

Test that a CP descriptor still works with notifyPropertyChange
when it is not setup correctly via Ember.defineProperty.

* [BUGFIX release] Fix emberjs#16427

Setup a non setup descriptor on access.

* upgrade broccoli-typescript-compiler

* convert ember-metal/transaction to typescript

* upgrade typescript-eslint-parser

* simplify exported type def

* [DOC release]Change name for Enumerable to comply with RFC 176

* [Feature] added module-unification route and route-test blueprints

* [BUGFIX canary] fix conditional

* Fix module cycle in @ember/engine package.

* Fix module cycle in @ember/application package.

* Fix module cycle in ember-runtime.

* [BUGFIX beta] bump glimmer

* More ts conversion.

* [DOC release] Update class_names_support.js to include binding classes to false properties

* reuse `isObject`

* correct `isProxy` and `setProxy`

* convert more ember-metal files to TS

* convert the rest of ember-metal to TS

* simplify chain logic

* Update the babel-plugin-debug-macros version in use.

* avoid using `isNone` internally

* move default values out of constructor in `ChainNode`

* Update to latest version of babel-plugin-debug-macros.

* Start enabling svelte builds WIP

* Extract shared utility for requiring typescript.

* Use `!!'<version string>` for deprecated feature versions.

This ensures that other typescript files detect the import is (properly)
a boolean.

* Cleanup deprecate feature parsing.

* Wrap `Ember.EXTEND_PROTOTYPES` for svelting.

* Wrap deprecated Ember.deprecate features for svelting.

* Wrap `sync` queue support for svelting.

* cleanup chains

* remove redundant `indexOf/lastIndexOf` from `NativeArray`

* Wrap `resolver` as function deprecation for svelting.

* Wrap Ember.Logger for svelting...

* Wrap positional param conflict support for svelting.

* Wrap `didInitAttrs` legacy support for svelte.

* Wrap propertyWillChange/propertyDidChange for svelting.

* Wrap `router.router` deprecation for svelting.

* Wrap `{{render` orphan `{{outlet}}` support for svelting.

* Wrap ArrayMixin's @each property for svelting.

* Wrap targetObject for svelting...

* Wrap `{{render}}` support for svelting.

* Wrap "fooBinding" support for svelting.

* Ensure @ember/deprecated-features ends up in template compiler build.

* Remove outdated `features.json` file.

* Add EMBER_GLIMMER_ANGLE_BRACKET_INVOCATION feature flag.

* Add basic "failing test" for simple angle bracket invocation.

* Modify component lookup to dasherize (and allow single word).

* Add AST transform to validate `...attributes`.

* Add more tests for angle bracket invocation.

* Ensure `moduleFor` allows for all caps feature names...

* deprecate `NativeArray#copy`

* Fixup tests to pass when feature flag is not runtime enableable.

When testing the alpha builds all features are compiled out, but using
`@feature` in the testing harness still thinks the feature will work :(

* Add ...attributes tests (when using tagless components).

* Wrap `didCreateElement` logic of curly component manager in a guard
(so that we only do things like add classes and whatnot when the
component we created uses a wrapped element.
* Added various tests for tagless components using `...attributes`

* conditionally add bindings related methods to meta

* Deprecate `Ember.Map`

* Deprecate `Ember.MapWithDefault`

* Deprecate `Ember.OrderedSet`

* Deprecate accessing jQuery.Event#originalEvent

Implements the deprecation message for user-land code accessing `originalEvent` on `jQuery.Event` instances, as proposed by RFC#294 (https://github.com/emberjs/rfcs/blob/master/text/0294-optional-jquery.md#introducing-ember-jquery-legacy-and-deprecating-jqueryevent-usage)

* Implemented copy/Copyable deprecation

* Cleaned up a couple of "pretty" issues the Travis build found.

* Ensure that if jQuery is explicitly disabled, Ember.$ is undefined, even if jquery is on the page.

* bump glimmer to 0.34.6

* convert ember-template-compiler to typescript

* Deprecate originalEvent only when jQuery is not explicitly enabled.

* Add URL to jQuery.Event deprecation

* remove redundant backtick in comment

* avoid boolean coercion in `meta`

* Update glimmer-vm to 0.34.8.

Main changes:

* No longer calls `didCreateElement` on the component manager for
  `...attributes`.
* Add support for `has-block` to be false with angle bracket invocation.
* Update glimmer-vm's own typescript config to be as strict as Embers.
* Update simple-html-tokenizer to allow an `@` in the tag name.
* Fix a number of issues with SSR related functionality.

* Update for glimmer-vm changes.

* Enable previously skipped `has-block` test
* Remove guard from `CurlyComponentManager#didCreateElement` (it is no
  longer called for each `...attributes` invocation).

* pass meta to `defineProperty`

* Bump glimmer-vm packages to 0.35.0.

* Account for breaking changes in glimmer-vm 0.35.0.

`Builder.prototype.dynamicComponent` added an additional argument
(`attr`) to support `...attributes` in dynamically angle bracket
invocations.

* Add tests for dynamic angle bracket invocation.

* Add 3.2.0 to CHANGELOG.

(cherry picked from commit d3d1f78)

* Add v3.3.0-beta.1 to CHANGELOG.md.

* Post release version bump.

* [FEATURE EMBER_GLIMMER_ANGLE_BRACKET_INVOCATION] Enable by default.

* [BUGFIX beta] avoid ordered set deprecation

* cleanup `toBool`

* [BUGFIX canary] Use customized dasherization for angle bracket invocations.

The [Angle Bracket Invocation
RFC](https://github.com/emberjs/rfcs/blob/master/text/0311-angle-bracket-invocation.md#tag-name)
specifically states:

> The tag name will be normalized using the dasherize function, which is
> the same rules used by existing use cases, such as service injections.
> This allows existing components to be invoked by the new syntax.

Unfortunately, using `Ember.String.dasherize` has (IMHO) fatal
consequences for angle bracket invocation.  Specifically, for an angle
bracket invocation as `<XFoo />` using `Ember.String.dasherize` we would
look up `xfoo` which IMHO is fundamentally flawed...

Changing `Ember.String.dasherize` has very wide spread impact, and is
likely to break existing apps in subtle ways. This implements a much
simpler dasherization system used exclusively for component lookup (with
its own independent cache).

* small cleanup mixins/array

* use `tryInvoke` in `ArrayMixin.invoke`

* [BUGFIX beta] Update glimmer-vm to 0.35.3.

* Cleanup template string indentation in angle bracket invocation tests.

* Add test ensuring implicit `this` paths are not allowed in angle invocations.

* remove redundant argument `reducerProperty`

* [Feature] Adds mixin blueprint for module unification

* bump backburner

* using Set for storing application instances

* Fixup edgecases for angle bracket component dasherization.

Also add a small test harness for the various edge cases that the
custom component name dasherization function needs to handle.

* cleanup `_getPath`

* added tests for `get` with paths

* [Feature] Update initializer blueprint for module unification

* [BUGFIX beta] Better error when a route name is not valid

Improves the error message shown when trying to define
a route with a ':' in the name.

Fixes emberjs#16642

* use `applyMixin` directly instead of using it through `Mixin`

* avoid boolean coercion in `property_set`

* Correct redirection to route api to routing guide

* update guides link

* [DOC release] Fix broken links to guides

* [BUGFIX beta] Throw error if run.bind receives no method

This commit uses the same logic as backburner.join to know
which method is being bound.

Fixes emberjs#16652

* make setup/teardown noop functions in descriptor

* Add v3.3.0-beta.2 to CHANGELOG
[ci skip]

(cherry picked from commit 2e2528a)

* [BUGFIX beta] Update glimmer-vm to 0.35.4.

Fixes issue with parsing a self closing element with no space between
unquoted attribute and self close.

```hbs
<FooBar data-foo={{someValue}}/>
```

* Wrap Ember.Map / Ember.OrderedSet / Ember.MapWithDefault for svelting.

* [BUGFIX] bring back isObject guard for ember-utils/is_proxy

`WeakSet.has` throws `TypeError` if argument is not an object:
https://www.ecma-international.org/ecma-262/6.0/#sec-weakset.prototype.has

While recent Chrome versions just returns `false`.

* Fix container destroy timing

* Ensure tests are run against Chrome 41

Chrome 41 (as far as I can tell) is the version of Chrome that googlebot
uses.  It is exceedingly difficult to track down issues related to
Googlebot bugs in Ember.js presently.

This ensures our tests run against the last known version of Googlebot's
browser

* Fix code style

* [BUGFIX beta] Allow Route#modelFor to work without routerMicrolib

* Test value parameter does not have to be a String

* Make CoreObject rely more on ES2015 class features and interop better.

* cleanup

* Update Custom Components feature to match final RFC.

* Removes view heirarchy updating (not included in RFC)
* Updates custom manager hook method names to match final RFC
* Add `capabilities` system (still very basic)
* Disentangle curly component manager from custom component manager.
* Add optional capabilities (`destructor` / `asyncLifecycleCallbacks`)
* Add temporary global (private on the global, public via modules API)
  for `capabilities`
* Migrate `setComponentManager` to use `WeakMap`'s instead of mutation

* Add v3.3.0-beta.3 to CHANGELOG
[ci skip]

(cherry picked from commit 60b68a3)

* [DEPRECATION] Deprecate `Component#sendAction` (RFC emberjs#335)

This also implicitly deprecated passing actions to the built-in inputs like `{{input enter="foo"}},
instead users must do `{{input enter=(action "foo")}}`.
There is a build-time deprecation that uses AST visitors to output precise information of file
and line the offending code is.
There is also a runtime-deprecation for cases that the AST deprecation can't catch.

* Add v3.2.1 to CHANGELOG
[ci skip]

(cherry picked from commit d8c83ff)

* CHANGELOG entries for `{{#each}}` & `{{#each-in}}`

* trying a workaround to FireFox

* [BUGFIX release] Refactor owner/container destroy.

Ensure `.destroy()` is called on all items in the container, _before_
marking `container.isDestroyed`. Only flush the caches after destroy is
finalized.

* Initialize meta with the right meta.proto based on the object passed in.

* Remove unused export.

* remove unused code

* add interop testing for compatibility

make meta.parent lazier

* Fix tests

* [DOC release] Restore documentation for component helper

* Update api url

* Add v3.2.2 to CHANGELOG
[ci skip]

(cherry picked from commit e0f32cc)

* Ensure meta._parent is initialized

* document Route `fullRouteName` property

I found this property when investigating a bug in ember-interactivity: elwayman02/ember-interactivity#52

* fixup: prettier

* Make EmberObject and Namespace use extends

* [FEATURE glimmer-custom-component-manager] Enable by default.

Discussed in todays core team meeting: 👍

* Remove unneeded things that create many mixins and merges.

* [perf] Only apply PrototypeMixin if it exists

Currently we are always applying the PrototypeMixin in `proto`, even if
it doesn't yet exist (as in the case of native classes). By checking to
see if it exists first, we should be able to avoid creating and applying
it unless it is necessary.

* also skip create on initial reopen

* Add v3.1.3 to CHANGELOG
[ci skip]

(cherry picked from commit 175fb43)

* Add v3.3.0-beta.4 to CHANGELOG
[ci skip]

(cherry picked from commit 4f54358)

* Convert ObjectProxy and ArrayProxy

* build release branches

* cleanup `forEachInDeps`

* extract and rename common methods

* [BUGFIX beta] Ensure tests from @ember/* are excluded from debug/prod builds.

* [BUGFIX] Allow setting length on ArrayProxy.

* Add failing tests for `A().invoke()` not returning an `A`.

* [BUGFIX] Ensure `ArrayMixin#invoke` returns an Ember.A.

This is a partial revert of bee179d, moving back to a manual `forEach`
so that we can control the return value a bit more. When prototype
extensions are disabled, we cannot rely on `this.map` to return an
extended array.

* [BUGFIX] Setting ArrayProxy#content in willDestroy resets length.

Prior to this change, `ArrayProxy.prototype.length` was marked as dirty
(and therefore recomputed) when `content` was set due to
`arrangedContent` being an alias of `content`, and `ArrayProxy`
implementing `PROPERTY_DID_CHANGE` to trap `arrangedContent` changes.

Unfortunately, `notifyPropertyChange` avoids notifying _some_ things
when the object is destroying. This results in the preexisting
`PROPERTY_DID_CHANGE` trap for `arrangedContent` is no longer called,
and therefore `length` is never marked as dirty.

This fixes the condition, by implementing a `content` trap in
`PROPERTY_DID_CHANGE` that marks length as dirty. The next time that
`length` is accessed it will do the normal work to recalculate.

* [BUGFIX] remove checks on init since ember-cli resolver sets namespace
after init.

* Add v3.3.0-beta.5 to CHANGELOG
[ci skip]

(cherry picked from commit 22811d6)

* (issue 16790) Added @static tag so that we can see defineProperty in the API doc

* [BUGFIX] Fix instance-initializer-test blueprint for RFC232

* cleanup `_lookupPartial`

* [CLEANUP] Convert dasherize test over to new style

* Rename `unknown` to `unusable`.

* [CLEANUP] Move off of QUnit.config.current

Moving off of QUnit.config.current in array helpers. Apart of emberjs#15988

* remove double ending line

* [BUGFIX] Centralize build versioning info

Make BUILD_TYPE only affect published buildType if on master so we don't
accidentally publish from lts/release branches over the current beta or
release.

Only use a tag as version if it is parseable by semver.

The build-for-publishing script uses git info instead of travis env.
@pixelhandler
Copy link
Contributor

@Turbo87 @cibernox @karthiicksiva @locks @mikerhyssmith @rwjblue @t-sauer @thoov is this still an issue, perhaps we should close, what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants