Skip to content

Commit

Permalink
Fix type-tests and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gitKrystan committed Jan 3, 2023
1 parent 46658ec commit a06900c
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 87 deletions.
54 changes: 36 additions & 18 deletions .eslintrc.js
@@ -1,5 +1,28 @@
'use strict';

const sharedTSOptions = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/strict',
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/method-signature-style': 'error',
'@typescript-eslint/no-confusing-void-expression': 'error',
'@typescript-eslint/no-redundant-type-constituents': 'error',
'@typescript-eslint/prefer-enum-initializers': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/promise-function-async': 'error',
},
};

module.exports = {
root: true,
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
Expand Down Expand Up @@ -48,29 +71,24 @@ module.exports = {
// ts files
{
files: ['**/*.ts'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/strict',
],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
plugins: ['@typescript-eslint'],
...sharedTSOptions,
},

// ts-tests files
{
files: ['type-tests/**/*.ts'],
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./type-tests/tsconfig.json'],
},
...sharedTSOptions,
rules: {
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/method-signature-style': 'error',
'@typescript-eslint/no-confusing-void-expression': 'error',
'@typescript-eslint/no-redundant-type-constituents': 'error',
'@typescript-eslint/prefer-enum-initializers': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
},

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -129,7 +129,7 @@ It will setup your test context the same way as `setupTest()`, and additionally:
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { hbs } from 'ember-cli-htmlbars';

module('GravatarImageComponent', function(hooks) {
setupRenderingTest(hooks);
Expand Down
2 changes: 1 addition & 1 deletion addon-test-support/adapter.ts
Expand Up @@ -5,7 +5,7 @@ import Ember from 'ember';

import * as QUnit from 'qunit';

import { isRecord, isTest } from 'ember-qunit/test-support/types/util';
import { isRecord, isTest } from './types/util';

function unhandledRejectionAssertion(current: unknown, error: unknown): void {
let message: string;
Expand Down
39 changes: 25 additions & 14 deletions addon-test-support/index.ts
Expand Up @@ -112,14 +112,9 @@ export function setupTest(
* Once invoked, all subsequent hooks.beforeEach and test invocations will
* have access to the following:
* * All of the methods / properties listed for `setupTest`
* * this.render(...) - Renders the provided template snippet returning a
* promise that resolves once rendering has completed
* * An importable render function that de-sugars into this.render will be
* the default output of blueprints
* * An importable render function
* * this.element - Returns the native DOM element representing the element
* that was rendered via this.render
* * this.$(...) - When jQuery is present, executes a jQuery selector with
* the current this.element as its root
*/
export function setupRenderingTest(
hooks: NestedHooks,
Expand Down Expand Up @@ -364,30 +359,38 @@ declare global {
* module's queue has emptied, it will not run this hook again.
*/
after<TC extends TestContext>(
fn: (this: TC, assert: Assert) => void | Promise<void>
fn:
| ((this: TC, assert: Assert) => void)
| ((this: TC, assert: Assert) => Promise<void>)
): void;

/**
* Runs after each test.
*/
afterEach<TC extends TestContext>(
fn: (this: TC, assert: Assert) => void | Promise<void>
fn:
| ((this: TC, assert: Assert) => void)
| ((this: TC, assert: Assert) => Promise<void>)
): void;

/**
* Runs before the first test.
*/
// SAFETY: this is just wildly, impossibly unsafe. QUnit cannot -- ever! --
before<TC extends TestContext>(
fn: (this: TC, assert: Assert) => void | Promise<void>
fn:
| ((this: TC, assert: Assert) => void)
| ((this: TC, assert: Assert) => Promise<void>)
): void;

/**
* Runs before each test.
*/
// SAFETY: this is just wildly, impossibly unsafe. QUnit cannot -- ever! --
beforeEach<TC extends TestContext>(
fn: (this: TC, assert: Assert) => void | Promise<void>
fn:
| ((this: TC, assert: Assert) => void)
| ((this: TC, assert: Assert) => Promise<void>)
): void;
}

Expand All @@ -413,7 +416,9 @@ declare global {
// `<template>` and local scope.
test<TC extends TestContext>(
name: string,
callback: (this: TC, assert: Assert) => void | Promise<unknown>
callback:
| ((this: TC, assert: Assert) => void)
| ((this: TC, assert: Assert) => Promise<void>)
): void;

/**
Expand All @@ -438,7 +443,9 @@ declare global {
// `<template>` and local scope.
only<TC extends TestContext>(
name: string,
callback: (this: TC, assert: Assert) => void | Promise<unknown>
callback:
| ((this: TC, assert: Assert) => void)
| ((this: TC, assert: Assert) => Promise<void>)
): void;

/**
Expand All @@ -457,7 +464,9 @@ declare global {
// `<template>` and local scope.
todo<TC extends TestContext>(
name: string,
callback: (this: TC, assert: Assert) => void | Promise<unknown>
callback:
| ((this: TC, assert: Assert) => void)
| ((this: TC, assert: Assert) => Promise<void>)
): void;

/**
Expand All @@ -479,7 +488,9 @@ declare global {
// `<template>` and local scope.
skip<TC extends TestContext>(
name: string,
callback?: (this: TC, assert: Assert) => void | Promise<unknown>
callback?:
| ((this: TC, assert: Assert) => void)
| ((this: TC, assert: Assert) => Promise<void>)
): void;
}
}
Expand Down
6 changes: 3 additions & 3 deletions addon-test-support/test-isolation-validation.ts
Expand Up @@ -12,8 +12,8 @@ import {

import * as QUnit from 'qunit';

import type { Test } from 'ember-qunit/test-support/types/util';
import { isTest } from 'ember-qunit/test-support/types/util';
import type { Test } from './types/util';
import { isTest } from './types/util';

/**
* Detects if a specific test isn't isolated. A test is considered
Expand All @@ -34,7 +34,7 @@ export function detectIfTestNotIsolated(test: Test, message = ''): void {
const { debugInfo } = getSettledState();

console.group(`${test.module.name}: ${test.testName}`);
debugInfo?.toConsole();
debugInfo.toConsole();
console.groupEnd();

assert('detectIfTestNotIsolated called on skipped test', !test.skip);
Expand Down
4 changes: 1 addition & 3 deletions docs/legacy.md
Expand Up @@ -18,7 +18,7 @@ and
### Component Integration Tests

```js
import hbs from 'htmlbars-inline-precompile';
import { hbs } from 'ember-cli-htmlbars';
import { test, moduleForComponent } from 'ember-qunit';

moduleForComponent('x-foo', {
Expand Down Expand Up @@ -143,8 +143,6 @@ test('It can set its child', function(assert) {
## Advanced Usage
### Setting the resolver

<!-- FIXME: setResolver is not actually exported from ember-qunit. It comes from @ember/test-helpers -->

```js
// if you don't have a custom resolver, do it like this:
setResolver(Ember.DefaultResolver.create({ namespace: App }));
Expand Down
4 changes: 2 additions & 2 deletions docs/migration.md
Expand Up @@ -208,7 +208,7 @@ Before:

```javascript
import { test, moduleForComponent } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import { hbs } from 'ember-cli-htmlbars';

moduleForComponent('GravatarImageComponent', {
integration: true
Expand All @@ -226,7 +226,7 @@ After:
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { hbs } from 'ember-cli-htmlbars';

module('GravatarImageComponent', function(hooks) {
setupRenderingTest(hooks);
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/basic-test.js
@@ -1,7 +1,7 @@
import { module, test } from 'qunit';
import EmberRouter from '@ember/routing/router';
import Route from '@ember/routing/route';
import hbs from 'htmlbars-inline-precompile';
import { hbs } from 'ember-cli-htmlbars';
import { setupApplicationTest } from 'ember-qunit';
import {
visit,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/setup-rendering-test-test.js
@@ -1,7 +1,7 @@
import { module, test } from 'qunit';
import Component from '@ember/component';
import { helper } from '@ember/component/helper';
import hbs from 'htmlbars-inline-precompile';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { setResolverRegistry } from '../helpers/resolver';
Expand Down
6 changes: 2 additions & 4 deletions tsconfig.json
Expand Up @@ -8,10 +8,8 @@
"paths": {
"dummy/tests/*": ["tests/*"],
"dummy/*": ["tests/dummy/app/*", "app/*"],
"ember-qunit": ["addon"],
"ember-qunit/*": ["addon/*"],
"ember-qunit/test-support": ["addon-test-support"],
"ember-qunit/test-support/*": ["addon-test-support/*"],
"ember-qunit": ["addon-test-support"],
"ember-qunit/*": ["addon-test-support/*"],
"*": ["types/*"]
}
},
Expand Down

0 comments on commit a06900c

Please sign in to comment.