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

Eslint plugin ember alpha v12 testing #1069

Merged
merged 3 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
},
"pnpm": {
"overrides": {
"ember-eslint-parser": "0.2.5",
"eslint-plugin-ember": "github:ember-cli/eslint-plugin-ember#master",
"@types/eslint": "7.29.0",
"mustache": "^4.2.0"
},
Expand Down
236 changes: 195 additions & 41 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions test-app/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Waiting on upstream fixes
*.gjs
*.gts

# unconventional js
/blueprints/*/files/
/vendor/
Expand Down
16 changes: 15 additions & 1 deletion test-app/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@ module.exports = {
overrides: [
...config.overrides,
{
files: ['**/*.ts'],
files: ['**/*.gts'],
plugins: ['ember'],
parser: 'ember-eslint-parser',
globals: {
// used in testing as a shorthand for <output>
out: true,
},
},
{
files: ['**/*.gjs'],
plugins: ['ember'],
parser: 'ember-eslint-parser',
},
{
files: ['**/*.{ts,gts}'],
rules: {
/**
* This one is incorrectly parsed for now, because
Expand Down
3 changes: 2 additions & 1 deletion test-app/app/components/glint-gts.gts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { tracked } from '@glimmer/tracking';
import { get } from '@ember/helper';

import { resource, use } from 'ember-resources';
import { Calculator, Doubler, overInvalidatingClock, clock } from './-resources';

import { Calculator, clock,Doubler, overInvalidatingClock } from './-resources';

const SomeClocks = <template>
{{!-- direct invocation --}}
Expand Down
4 changes: 2 additions & 2 deletions test-app/app/components/util/remote-data.gts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';

import { use, resource } from 'ember-resources';
import { remoteData, RemoteData } from 'ember-resources/util/remote-data';
import { resource,use } from 'ember-resources';
import { RemoteData,remoteData } from 'ember-resources/util/remote-data';

const formatError = (error: unknown) => {
return `Hey!, ${error}`;
Expand Down
2 changes: 1 addition & 1 deletion test-app/tests/core/function-resource/clock-test.gts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tracked } from '@glimmer/tracking';
import { destroy } from '@ember/destroyable';
// @ts-ignore
// @ts-ignore @ember/helper does not provide types :(
import { hash } from '@ember/helper';
import { clearRender, find, render, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
Expand Down
12 changes: 10 additions & 2 deletions test-app/tests/core/function-resource/composition-test.gts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { render, rerender, clearRender, settled } from '@ember/test-helpers';
import { tracked } from '@glimmer/tracking';
import { clearRender, render, rerender, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import { resource, cell, resourceFactory } from 'ember-resources';
import { cell, resource, resourceFactory } from 'ember-resources';

// Will need to be a class for .current flattening / auto-rendering
interface Reactive<Value> {
Expand Down Expand Up @@ -44,11 +44,13 @@ module('Core | (function) resource | use | rendering', function (hooks) {
await render(<template><time>{{Stopwatch}}</time></template>);

let first = formatter.format(Date.now());

assert.dom('time').hasText(first);

await wait(1010);

let second = formatter.format(Date.now());

assert.dom('time').hasText(second);
assert.notEqual(first, second);
});
Expand Down Expand Up @@ -125,11 +127,13 @@ module('Core | (function) resource | use | rendering', function (hooks) {
await render(<template><time>{{Stopwatch 250}}</time></template>);

let first = formatter.format(Date.now());

assert.dom('time').hasText(first);

await wait(1010);

let second = formatter.format(Date.now());

assert.dom('time').hasText(second);
assert.notEqual(first, second);
});
Expand Down Expand Up @@ -171,6 +175,7 @@ module('Core | (function) resource | use | rendering', function (hooks) {

const Outer = resource(({ on }) => {
let outerValue = state.outerValue;

assert.step(`Outer:setup ${outerValue}`);

on.cleanup(() => {
Expand All @@ -179,12 +184,14 @@ module('Core | (function) resource | use | rendering', function (hooks) {

return () => {
assert.step(`Outer:value:${state.value}`);

return state.value;
};
});

const Inner = resource(({ on, use }) => {
let innerValue = state.innerValue;

assert.step(`Inner:setup ${innerValue}`);

let result = use(Outer);
Expand All @@ -195,6 +202,7 @@ module('Core | (function) resource | use | rendering', function (hooks) {

return () => {
assert.step(`Inner:value:${result.current}`);

return result.current;
};
});
Expand Down
2 changes: 1 addition & 1 deletion test-app/tests/core/function-resource/rendering-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { clearRender, render, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import { resource, use, cell } from 'ember-resources';
import { cell,resource, use } from 'ember-resources';

module('Utils | (function) resource | rendering', function (hooks) {
setupRenderingTest(hooks);
Expand Down
8 changes: 4 additions & 4 deletions test-app/tests/core/rendering-test.gts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { tracked } from '@glimmer/tracking';
// @ts-ignore @ember/modifier does not provide types :(
import { on } from '@ember/modifier';
import { click, render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

// @ts-ignore
import { on } from '@ember/modifier';

import { Resource, resourceFactory, resource, cell, use } from 'ember-resources';
import { cell, Resource, resource, resourceFactory, use } from 'ember-resources';

module('Core | Resource | rendering', function (hooks) {
setupRenderingTest(hooks);
Expand Down Expand Up @@ -95,6 +94,7 @@ module('Core | Resource | rendering', function (hooks) {
return resource(({ on }) => {
assert.step(`setup: ${id}`);
on.cleanup(() => assert.step(`cleanup: ${id}`));

return id;
});
});
Expand Down
4 changes: 2 additions & 2 deletions test-app/tests/modifier/rendering-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { render, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import { resource, cell } from 'ember-resources';
import { cell,resource } from 'ember-resources';
import { modifier } from 'ember-resources/modifier';

module('modifier | rendering', function (hooks) {
setupRenderingTest(hooks);

test('throws an error if no argument is passed', async function (assert) {
assert.throws(() => {
// @ts-expect-error
// @ts-expect-error - deliberately testing an error here
modifier();
}, /modifier\(\) must be invoked with a function/);
});
Expand Down
9 changes: 4 additions & 5 deletions test-app/tests/service/rendering-test.gts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import Component from '@glimmer/component';
import { find,render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { render, find } from '@ember/test-helpers';
import { setupRenderingTest } from 'ember-qunit';

import { cell, Resource, resource } from 'ember-resources';
import { service, serviceOverride } from 'ember-resources/service';

import type Owner from '@ember/owner';

// This export is marked as @internal, so it is not present in
// the built d.ts files.
// @ts-expect-error
// @ts-expect-error - types are deliberately not exported
import { __secret_service_cache__ } from 'ember-resources/service';

import type Owner from '@ember/owner';

const CACHE = __secret_service_cache__ as WeakMap<Owner, Map<object, any>>;

module('@service | rendering', function (hooks) {
Expand Down
2 changes: 1 addition & 1 deletion test-app/tests/utils/fps/rendering-test.gts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
// @ts-ignore
// @ts-ignore @ember/modifier does not provide types :(
import { on } from '@ember/modifier';
import { click, find, render } from '@ember/test-helpers';
import { module, test } from 'qunit';
Expand Down
8 changes: 4 additions & 4 deletions test-app/tests/utils/function/rendering-test.gts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { click, render, settled } from '@ember/test-helpers';
// @ts-ignore
import { setOwner } from '@ember/application';
// @ts-ignore @ember/modifier does not provide types :(
import { on } from '@ember/modifier';
import { click, render, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { setOwner } from '@ember/application';

import { cell, use, resource, resourceFactory } from 'ember-resources';
import { cell, resource, resourceFactory,use } from 'ember-resources';
import { trackedFunction } from 'ember-resources/util/function';

const timeout = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
Expand Down
3 changes: 3 additions & 0 deletions test-app/tests/utils/function/timing-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module('Utils | trackedFunction | timing', function (hooks) {
step(`fn:begin:${value}`);
await Promise.resolve();
step(`fn:end:${value}`);

return `yay:${value}`;
}

Expand Down Expand Up @@ -66,9 +67,11 @@ module('Utils | trackedFunction | timing', function (hooks) {
class Example extends Component<{ Args: { value: unknown } }> {
request = trackedFunction(this, async () => {
let value = this.args.value;

step(`fn:begin:${value}`);
await Promise.resolve();
step(`fn:end:${value}`);

return `yay:${value}`;
});

Expand Down
4 changes: 2 additions & 2 deletions test-app/tests/utils/keep-latest/rendering-test.gts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { tracked } from '@glimmer/tracking';
// @ts-ignore
// @ts-ignore @ember/helper does not provide types :(
import { fn, hash } from '@ember/helper';
import { module, test } from 'qunit';
import { render, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import { trackedFunction } from 'ember-resources/util/function';
Expand Down
6 changes: 3 additions & 3 deletions test-app/tests/utils/remote-data/rendering-test.gts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { tracked } from '@glimmer/tracking';
import { click, render, settled } from '@ember/test-helpers';
// @ts-ignore
// @ts-ignore @ember/modifier does not provide types :(
import { on } from '@ember/modifier';
import { click, render, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';

import { setupMSW } from 'test-app/tests/msw';
import { RemoteData } from 'ember-resources/util/remote-data';
import { setupMSW } from 'test-app/tests/msw';

let data = [
{ id: '1', type: 'blogs', attributes: { name: `name:1` } },
Expand Down
Loading