diff --git a/addon/package.json b/addon/package.json index cddb8663..236cf9d5 100644 --- a/addon/package.json +++ b/addon/package.json @@ -25,9 +25,21 @@ "license": "MIT", "author": "Santiago Ferreira", "exports": { - ".": "./dist/index.js", - "./*": "./dist/*", - "./addon-main.js": "./addon-main.js" + ".": { + "import": "./dist/index.js", + "require": "./dist/index.js", + "types": "./types.d.ts" + }, + "./*": { + "import": "./dist/*", + "require": "./dist/*", + "types": "./types.d.ts" + }, + "./addon-main.js": { + "import": "./addon-main.js", + "require": "./addon-main.js", + "types": "./types.d.ts" + } }, "types": "types.d.ts", "files": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f4091a04..ceed8d13 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -81,6 +81,7 @@ importers: '@embroider/test-setup': ^1.8.0 '@glimmer/component': ^1.1.2 '@glimmer/tracking': ^1.1.2 + '@tsconfig/ember': ^2.0.0 '@types/ember': ^3.1.1 '@types/ember-qunit': ^3.4.13 '@types/ember-resolver': ^5.0.10 @@ -150,6 +151,7 @@ importers: '@embroider/test-setup': 1.8.3 '@glimmer/component': 1.1.2_@babel+core@7.21.3 '@glimmer/tracking': 1.1.2 + '@tsconfig/ember': 2.0.0 '@types/ember': 3.16.7 '@types/ember-qunit': 3.4.15 '@types/ember-resolver': 5.0.13 @@ -2155,6 +2157,10 @@ packages: engines: {node: '>= 6'} dev: true + /@tsconfig/ember/2.0.0: + resolution: {integrity: sha512-RzbDYYcjxVdG8Ki0xe99HN3+nHTZe6EBgw6N7B3yup7QogVFQQxA9nY7X80j1XzF15xqetwWiYfAjv5lkkp0/A==} + dev: true + /@types/babel__core/7.20.0: resolution: {integrity: sha512-+n8dL/9GWblDO0iU6eZAwEIJVr5DWigtle+Q6HLOrh/pdbXOhOtqzq8VPPE2zvNJzSKY4vH/z3iT3tn0A3ypiQ==} dependencies: @@ -8791,7 +8797,7 @@ packages: resolution: {integrity: sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==} engines: {node: '>= 4.0'} os: [darwin] - deprecated: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2. + deprecated: The v1 package contains DANGEROUS / INSECURE binaries. Upgrade to safe fsevents v2 requiresBuild: true dependencies: bindings: 1.5.0 diff --git a/test-app/config/ember-try.js b/test-app/config/ember-try.js index be55d6e2..a2167865 100644 --- a/test-app/config/ember-try.js +++ b/test-app/config/ember-try.js @@ -27,6 +27,7 @@ module.exports = async function () { name: 'ember-release', npm: { devDependencies: { + '@ember/string': '^3.1.1', 'ember-source': await getChannelURL('release'), }, }, @@ -36,10 +37,29 @@ module.exports = async function () { }), }, }, + { + name: 'ember-release-typescript-5', + npm: { + devDependencies: { + '@ember/string': '^3.1.1', + '@tsconfig/ember': '^3.0.0', + 'ember-cli-typescript': '^5.2.1', + 'ember-resolver': '^10.1.1', + 'ember-source': await getChannelURL('release'), + typescript: '^5.1.6', + }, + }, + env: { + EMBER_OPTIONAL_FEATURES: JSON.stringify({ + 'jquery-integration': false, + }), + }, + }, { name: 'ember-beta', npm: { devDependencies: { + '@ember/string': '^3.1.1', 'ember-source': await getChannelURL('beta'), }, }, diff --git a/test-app/package.json b/test-app/package.json index e7e69519..bc3f5b25 100644 --- a/test-app/package.json +++ b/test-app/package.json @@ -36,6 +36,7 @@ "@embroider/test-setup": "^1.8.0", "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", + "@tsconfig/ember": "^2.0.0", "@types/ember": "^3.1.1", "@types/ember-qunit": "^3.4.13", "@types/ember-resolver": "^5.0.10", diff --git a/test-app/tests/acceptance/collection-test.ts b/test-app/tests/acceptance/collection-test.ts index 3d1ee1fb..e4943f89 100644 --- a/test-app/tests/acceptance/collection-test.ts +++ b/test-app/tests/acceptance/collection-test.ts @@ -13,7 +13,7 @@ module('Acceptance | collection', function (hooks) { setupApplicationTest(hooks); test(`allows to traverse nodes while they don't exist`, async function (assert) { - await page.visit().numbers[2].click(); + await page.visit().numbers[2]?.click(); assert.ok(1, 'exception is not thrown'); }); diff --git a/test-app/tests/unit/-private/composition-test.ts b/test-app/tests/unit/-private/composition-test.ts index fecd89a6..399b6609 100644 --- a/test-app/tests/unit/-private/composition-test.ts +++ b/test-app/tests/unit/-private/composition-test.ts @@ -157,11 +157,11 @@ module('Unit | composition', function () { getPageObjectDefinition({}); assert.true(false); } catch (e) { - assert.strictEqual(e.toString(), 'Error: cannot get the page object definition from a node that is not a page object'); + assert.strictEqual(e?.toString(), 'Error: cannot get the page object definition from a node that is not a page object'); } }); - module('all properties via compsition', function (hooks) { + module('all properties via composition', function (hooks) { setupRenderingTest(hooks); test('can alias through composition', async function (assert) { diff --git a/test-app/tests/unit/-private/properties/collection-test.ts b/test-app/tests/unit/-private/properties/collection-test.ts index a6edc6b5..e2e95309 100644 --- a/test-app/tests/unit/-private/properties/collection-test.ts +++ b/test-app/tests/unit/-private/properties/collection-test.ts @@ -88,13 +88,13 @@ module('collection', function(hooks) { let array = page.foo.toArray(); assert.equal(array.length, 2); - assert.equal(array[0].text, 'Lorem'); - assert.equal(array[1].text, 'Ipsum'); + assert.equal(array[0]?.text, 'Lorem'); + assert.equal(array[1]?.text, 'Ipsum'); let proxyArray = page.foo.toArray(); assert.equal(proxyArray.length, 2); - assert.equal(proxyArray[0].text, 'Lorem'); - assert.equal(proxyArray[1].text, 'Ipsum'); + assert.equal(proxyArray[0]?.text, 'Lorem'); + assert.equal(proxyArray[1]?.text, 'Ipsum'); }); test('produces an iterator for items', async function(this: TestContext, assert) { @@ -548,7 +548,7 @@ module('collection', function(hooks) { `); assert.deepEqual(page.foo.filter((i) => i.isSpecial).map((i) => i.text), ['Lorem']); - assert.deepEqual(page.foo.filter((i) => i.isFoo as any).map((i) => i.text), []); + assert.deepEqual(page.foo.filter((i) => i['isFoo'] as any).map((i) => i.text), []); }); test('filterBy works correctly', async function(this: TestContext, assert) { @@ -578,7 +578,7 @@ module('collection', function(hooks) { Ipsum `); - assert.equal(page.foo[0].text, 'Lorem'); - assert.equal(page.foo[1].text, 'Ipsum'); + assert.equal(page.foo[0]?.text, 'Lorem'); + assert.equal(page.foo[1]?.text, 'Ipsum'); }); }); diff --git a/test-app/tests/unit/-private/properties/create-test.ts b/test-app/tests/unit/-private/properties/create-test.ts index 2bb89366..28b6c0be 100644 --- a/test-app/tests/unit/-private/properties/create-test.ts +++ b/test-app/tests/unit/-private/properties/create-test.ts @@ -94,7 +94,7 @@ module('create', function () { // @ts-expect-error violate types to check if it fails in weakly-typed envs create(''); assert.true(false, 'should error'); - } catch (e) { + } catch (e: any) { assert.strictEqual(e.message, 'Definition can not be a string'); } }); diff --git a/test-app/tests/unit/-private/properties/fillable-test.ts b/test-app/tests/unit/-private/properties/fillable-test.ts index e258dd1f..56b25e24 100644 --- a/test-app/tests/unit/-private/properties/fillable-test.ts +++ b/test-app/tests/unit/-private/properties/fillable-test.ts @@ -59,7 +59,7 @@ module('fillable', function(hooks) { foo: fillable() }); - await this.createTemplate(`
${this.template}
`); + await this.createTemplate(`
${this['template']}
`); await page.foo(clue, expectedText); @@ -80,10 +80,10 @@ module('fillable', function(hooks) { foo: fillable() }); - this.attrName = attrName; + this[attrName] = attrName; await this.createTemplate(`
-
+
`); await page.foo(clue, expectedText); diff --git a/test-app/tests/unit/-private/properties/getter-test.ts b/test-app/tests/unit/-private/properties/getter-test.ts index 6072b4cf..a01373ca 100644 --- a/test-app/tests/unit/-private/properties/getter-test.ts +++ b/test-app/tests/unit/-private/properties/getter-test.ts @@ -79,7 +79,7 @@ module('getter', function(hooks) { page.foo; assert.true(false); } catch (e) { - assert.strictEqual(e.toString(), `Error: Argument passed to \`getter\` must be a function. + assert.strictEqual(e?.toString(), `Error: Argument passed to \`getter\` must be a function. PageObject: \'page.foo\'`) } @@ -98,7 +98,7 @@ PageObject: \'page.foo\'`) page.foo; assert.true(false); } catch (e) { - assert.strictEqual(e.toString(), `Error: custom error message + assert.strictEqual(e?.toString(), `Error: custom error message PageObject: \'page.foo\'`) } diff --git a/test-app/tests/unit/-private/properties/visitable-test.ts b/test-app/tests/unit/-private/properties/visitable-test.ts index 8deeeda6..ebe01658 100644 --- a/test-app/tests/unit/-private/properties/visitable-test.ts +++ b/test-app/tests/unit/-private/properties/visitable-test.ts @@ -84,7 +84,7 @@ module('visitable', function(hooks) { assert.false(true, 'visit should have failed'); } catch (e) { - assert.strictEqual(e.toString(), `Error: Failed to visit URL '/non-existing-url/value' + assert.strictEqual(e?.toString(), `Error: Failed to visit URL '/non-existing-url/value' PageObject: 'page.foo(\"[object Object]\")' Selector: '.scope'`); diff --git a/test-app/tsconfig.json b/test-app/tsconfig.json index 1f5edfeb..c819eb84 100644 --- a/test-app/tsconfig.json +++ b/test-app/tsconfig.json @@ -1,47 +1,18 @@ { + "extends": "@tsconfig/ember/tsconfig.json", "compilerOptions": { - "target": "es2020", - "allowJs": true, - "moduleResolution": "node", - "allowSyntheticDefaultImports": false, - "noImplicitAny": true, - "noImplicitThis": true, - "alwaysStrict": true, - "strictNullChecks": true, - "strictPropertyInitialization": true, - "noFallthroughCasesInSwitch": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noImplicitReturns": true, - "noEmitOnError": true, - "noEmit": true, - "inlineSourceMap": true, - "inlineSources": true, + // The combination of `baseUrl` with `paths` allows Ember's classic package + // layout, which is not resolvable with the Node resolution algorithm, to + // work with TypeScript. "baseUrl": ".", - "module": "es6", - "experimentalDecorators": true, "paths": { - "test-app/tests/*": [ - "tests/*" - ], - "test-app/*": [ - "app/*" - ], - "ember-cli-page-object": [ - "addon" - ], - "ember-cli-page-object/*": [ - "addon/*" - ], - "ember-cli-page-object/test-support": [ - "addon-test-support" - ], - "ember-cli-page-object/test-support/*": [ - "addon-test-support/*" - ], - "*": [ - "types/*" - ] + "test-app/tests/*": ["tests/*"], + "test-app/*": ["app/*"], + "ember-cli-page-object": ["addon"], + "ember-cli-page-object/*": ["addon/*"], + "ember-cli-page-object/test-support": ["addon-test-support"], + "ember-cli-page-object/test-support/*": ["addon-test-support/*"], + "*": ["types/*"] } }, "include": [