-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
base: main
Are you sure you want to change the base?
Changes from all commits
c94d02b
dbbeb9c
184ddd1
48958d6
2ac042f
874ba77
db410ef
4c66f5c
2744e02
a11495e
588c69f
a9f4231
88f8a5f
77765f9
e251730
434068f
b76fb1f
6d9a48d
d114caa
8c419e2
2039091
9f278ae
c658add
8a2fa12
aa12055
815c4c0
f68c09e
f9c8fb0
e823763
a2ffc43
f13fd8f
5073442
55a235f
2f420c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
!.* | ||
.*/ | ||
.eslintcache | ||
/.yalc* | ||
/yalc.lock | ||
|
||
# ember-try | ||
/.node_modules.ember-try/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'], | ||
|
@@ -45,6 +68,30 @@ module.exports = { | |
extends: ['plugin:node/recommended'], | ||
}, | ||
|
||
// ts files | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ | |
/npm-debug.log* | ||
/testem.log | ||
/yarn-error.log | ||
/.yalc* | ||
/yalc.lock | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
!.* | ||
.eslintcache | ||
.lint-todo/ | ||
/.yalc* | ||
/yalc.lock | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/ | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
There was a problem hiding this comment.
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