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

WIP: Convert to TypeScript #994

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c94d02b
REVERT ME: Dev setup
gitKrystan Dec 5, 2022
dbbeb9c
Add ember-cli-typescript
gitKrystan Dec 5, 2022
184ddd1
Check tsc as lint step
gitKrystan Dec 5, 2022
48958d6
Configure ts/eslint strictness
gitKrystan Dec 5, 2022
2ac042f
Rename adddon-test-support/adapter to TS
gitKrystan Dec 5, 2022
874ba77
Fix type checking errors for adapter.ts
gitKrystan Dec 6, 2022
db410ef
Rename addon-test-support/test-isoliation-validation to TS
gitKrystan Dec 6, 2022
4c66f5c
Fix type checking errors for test-isolation-validation.ts
gitKrystan Dec 10, 2022
2744e02
Rename qunit-configuration to TS
gitKrystan Dec 10, 2022
a11495e
Fix type checking errors for qunit-configuration
gitKrystan Dec 10, 2022
588c69f
Rename test-loader to TS
gitKrystan Dec 10, 2022
a9f4231
Fix type checking errors on test-loader
gitKrystan Dec 10, 2022
88f8a5f
Rename index to TS
gitKrystan Dec 10, 2022
77765f9
Fix type checking errors on index
gitKrystan Dec 10, 2022
e251730
Move ember-source/types imports
gitKrystan Dec 12, 2022
434068f
Merge info from ambient types
gitKrystan Jan 3, 2023
b76fb1f
Fix type-tests and lint
gitKrystan Jan 3, 2023
6d9a48d
Fix typesVersions
gitKrystan Jan 3, 2023
d114caa
Clean up waitForSettled types
gitKrystan Jan 3, 2023
8c419e2
Use exported @ember/test-helpers options
gitKrystan Jan 3, 2023
2039091
Add fixme
gitKrystan Jan 3, 2023
9f278ae
Set isTypeScriptProject to true
gitKrystan Jan 4, 2023
c658add
Use ember-cli-test-loader types
gitKrystan Jan 4, 2023
8a2fa12
Use updated qunit types
gitKrystan Jan 5, 2023
aa12055
Don't use private timeout type
gitKrystan Jan 5, 2023
815c4c0
Use override for moduleLoadFailure override
gitKrystan Jan 5, 2023
f68c09e
Remove FIXMEs from ember classic junk
gitKrystan Jan 5, 2023
f9c8fb0
Remove remaining FIXMEs
gitKrystan Jan 6, 2023
e823763
Revert to ambient ember-cli-test-loader types
gitKrystan Jan 30, 2023
a2ffc43
Fix config
gitKrystan Jan 31, 2023
f13fd8f
Upgrade @typescript-eslint dependencies
gitKrystan Jan 31, 2023
5073442
Use local @ember/test-helpers
gitKrystan Feb 27, 2023
55a235f
Upgrade @typescript-eslint/*
gitKrystan Feb 27, 2023
2f420c5
Use @ember/test-helpers master and node 16
gitKrystan Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ember-cli
Expand Up @@ -11,5 +11,5 @@
Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
*/
"isTypeScriptProject": false
"isTypeScriptProject": true
}
2 changes: 2 additions & 0 deletions .eslintignore
Expand Up @@ -15,6 +15,8 @@
!.*
.*/
.eslintcache
/.yalc*
/yalc.lock
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can revert once emberjs/ember-test-helpers#1319 is released


# ember-try
/.node_modules.ember-try/
Expand Down
47 changes: 47 additions & 0 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 @@ -45,6 +68,30 @@ module.exports = {
extends: ['plugin:node/recommended'],
},

// ts files
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove this if you don't like UBER-STRICTNESS, but I find it useful during conversion at least

files: ['**/*.ts'],
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
...sharedTSOptions,
},

// ts-tests files
{
files: ['type-tests/**/*.ts'],
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./type-tests/tsconfig.json'],
},
...sharedTSOptions,
rules: {
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
},

// test files
{
files: ['tests/**/*.js'],
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -20,6 +20,9 @@
/npm-debug.log*
/testem.log
/yarn-error.log
/.yalc*
/yalc.lock
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can revert once emberjs/ember-test-helpers#1319 is released

/.vscode*

# ember-try
/.node_modules.ember-try/
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Expand Up @@ -15,6 +15,8 @@
!.*
.eslintcache
.lint-todo/
/.yalc*
/yalc.lock
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can revert once emberjs/ember-test-helpers#1319 is released


# ember-try
/.node_modules.ember-try/
Expand Down
80 changes: 0 additions & 80 deletions addon-test-support/adapter.js

This file was deleted.

106 changes: 106 additions & 0 deletions addon-test-support/adapter.ts
@@ -0,0 +1,106 @@
import { assert } from '@ember/debug';
import type EmberTestAdapter from '@ember/test/adapter';
import hasEmberVersion from '@ember/test-helpers/has-ember-version';
import Ember from 'ember';

import * as QUnit from 'qunit';

import { isRecord, isTest } from './types/util';

function unhandledRejectionAssertion(current: unknown, error: unknown): void {
let message: string;
let source: string | undefined;

if (
isRecord(error) &&
'message' in error &&
typeof error['message'] === 'string'
) {
message = error['message'];
source = typeof error['stack'] === 'string' ? error['stack'] : undefined;
} else if (typeof error === 'string') {
message = error;
source = 'unknown source';
} else {
message = 'unhandledRejection occurred, but it had no message';
source = 'unknown source';
}

assert(
'expected current test to have an assert',
isTest(current) && 'assert' in current
);
current.assert.pushResult({
result: false,
actual: false,
expected: true,
message: message,
source,
});
}

export function nonTestDoneCallback(): void {
// no-op
}

interface QUnitAdapter extends EmberTestAdapter {
doneCallbacks: Array<{ test: unknown; done: () => void }>;
qunit: QUnit;
}

// @ts-expect-error `extend` does not exist on Adapter
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
let Adapter = Ember.Test.Adapter.extend({
init(this: QUnitAdapter) {
this.doneCallbacks = [];
this.qunit ??= QUnit;
},

asyncStart(this: QUnitAdapter) {
const currentTest: unknown = this.qunit.config.current;
const done =
isTest(currentTest) && 'assert' in currentTest
? currentTest.assert.async()
: nonTestDoneCallback;
this.doneCallbacks.push({ test: currentTest, done });
},

asyncEnd(this: QUnitAdapter) {
const currentCallback = this.doneCallbacks.pop();

if (!currentCallback) {
throw new Error(
'Adapter asyncEnd called when no async was expected. Please create an issue in ember-qunit.'
);
}

const { test, done } = currentCallback;

// In future, we should explore fixing this at a different level, specifically
// addressing the pairing of asyncStart/asyncEnd behavior in a more consistent way.
if (test === this.qunit.config.current) {
done();
}
},

// clobber default implementation of `exception` will be added back for Ember
// < 2.17 just below...
exception: null,
}) as QUnitAdapter;

// Ember 2.17 and higher do not require the test adapter to have an `exception`
// method When `exception` is not present, the unhandled rejection is
// automatically re-thrown and will therefore hit QUnit's own global error
// handler (therefore appropriately causing test failure)
if (!hasEmberVersion(2, 17)) {
// @ts-expect-error `extend` does not exist on Adapter
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
Adapter = Adapter.extend({
exception(error: unknown) {
const currentTest: unknown = QUnit.config.current;
unhandledRejectionAssertion(currentTest, error);
},
}) as QUnitAdapter;
}

export default Adapter;