-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add some TS component blueprint tests #20771
Open
Windvis
wants to merge
4
commits into
emberjs:main
Choose a base branch
from
Windvis:ts-blueprint-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c005496
Patch `ember-cli-blueprint-test-helpers` to allow extra arguments
Windvis 7ff7ba0
Add some TS component blueprint tests
Windvis dd62d35
Remove the `.ts` suffix when generating .ts components
Windvis f41d8ae
Run the blueprint tests in parallel in CI
Windvis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,290 @@ | ||
'use strict'; | ||
|
||
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers'); | ||
const setupTestHooks = blueprintHelpers.setupTestHooks; | ||
const emberNew = blueprintHelpers.emberNew; | ||
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy; | ||
|
||
const chai = require('ember-cli-blueprint-test-helpers/chai'); | ||
const expect = chai.expect; | ||
|
||
const fixture = require('../helpers/fixture'); | ||
|
||
function glimmerComponentContents(componentName = 'Foo') { | ||
return `import Component from '@glimmer/component'; | ||
|
||
export interface ${componentName}Signature { | ||
// The arguments accepted by the component | ||
Args: {}; | ||
// Any blocks yielded by the component | ||
Blocks: { | ||
default: [] | ||
}; | ||
// The element to which \`...attributes\` is applied in the component template | ||
Element: null; | ||
} | ||
|
||
export default class ${componentName} extends Component<${componentName}Signature> {} | ||
`; | ||
} | ||
|
||
const emberComponentContents = `import Component from '@ember/component'; | ||
|
||
|
||
export default Component.extend({}); | ||
`; | ||
|
||
const templateOnlyContents = `import templateOnly from '@ember/component/template-only'; | ||
|
||
export interface FooSignature { | ||
// The arguments accepted by the component | ||
Args: {}; | ||
// Any blocks yielded by the component | ||
Blocks: { | ||
default: [] | ||
}; | ||
// The element to which \`...attributes\` is applied in the component template | ||
Element: null; | ||
} | ||
|
||
export default templateOnly<FooSignature>(); | ||
`; | ||
|
||
describe('TS Blueprint: component', function () { | ||
setupTestHooks(this); | ||
|
||
describe('in app', function () { | ||
beforeEach(function () { | ||
return emberNew({ cliArgs: ['--typescript'] }); | ||
}); | ||
|
||
it('component foo', function () { | ||
return emberGenerateDestroy(['component', 'foo'], (_file) => { | ||
expect(_file('app/components/foo.ts')).to.not.exist; | ||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
// Octane default | ||
it('component foo --component-structure=flat --component-class=@glimmer/component', function () { | ||
return emberGenerateDestroy( | ||
[ | ||
'component', | ||
'--component-structure', | ||
'flat', | ||
'--component-class', | ||
'@glimmer/component', | ||
'foo', | ||
], | ||
(_file) => { | ||
expect(_file('app/components/foo.ts')).to.equal(glimmerComponentContents()); | ||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --component-structure=flat', function () { | ||
return emberGenerateDestroy( | ||
['component', '--component-structure', 'flat', 'foo'], | ||
(_file) => { | ||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --component-structure=nested', function () { | ||
return emberGenerateDestroy( | ||
['component', '--component-structure', 'nested', 'foo'], | ||
(_file) => { | ||
expect(_file('app/components/foo/index.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --component-class=@ember/component', function () { | ||
return emberGenerateDestroy( | ||
['component', '--component-class', '@ember/component', 'foo'], | ||
(_file) => { | ||
expect(_file('app/components/foo.ts')).to.equal(emberComponentContents); | ||
|
||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --component-class=@glimmer/component', function () { | ||
return emberGenerateDestroy( | ||
['component', '--component-class', '@glimmer/component', 'foo'], | ||
(_file) => { | ||
expect(_file('app/components/foo.ts')).to.equal(glimmerComponentContents()); | ||
|
||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --component-class=@ember/component/template-only', function () { | ||
return emberGenerateDestroy( | ||
['component', '--component-class', '@ember/component/template-only', 'foo'], | ||
(_file) => { | ||
expect(_file('app/components/foo.ts')).to.equal(templateOnlyContents); | ||
|
||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --no-component-class', function () { | ||
return emberGenerateDestroy(['component', '--no-component-class', 'foo'], (_file) => { | ||
expect(_file('app/components/foo.ts')).to.not.exist; | ||
|
||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it('component x-foo', function () { | ||
return emberGenerateDestroy(['component', 'x-foo'], (_file) => { | ||
expect(_file('app/components/x-foo.ts')).to.not.exist; | ||
expect(_file('app/components/x-foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/x-foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'x-foo', | ||
componentInvocation: 'XFoo', | ||
}, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it('component x-foo.ts', function () { | ||
return emberGenerateDestroy(['component', 'x-foo.ts'], (_file) => { | ||
expect(_file('app/components/x-foo.ts')).to.not.exist; | ||
expect(_file('app/components/x-foo.js.js')).to.not.exist; | ||
expect(_file('app/templates/components/x-foo.ts.hbs')).to.not.exist; | ||
expect(_file('tests/integration/components/x-foo-test.ts.ts')).to.not.exist; | ||
|
||
expect(_file('app/components/x-foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/x-foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'x-foo', | ||
componentInvocation: 'XFoo', | ||
}, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it('component foo/x-foo', function () { | ||
return emberGenerateDestroy(['component', 'foo/x-foo'], (_file) => { | ||
expect(_file('app/components/foo/x-foo.ts')).to.not.exist; | ||
expect(_file('app/components/foo/x-foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo/x-foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo/x-foo', | ||
componentInvocation: 'Foo::XFoo', | ||
}, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it('component foo/x-foo --component-class="@glimmer/component"', function () { | ||
return emberGenerateDestroy( | ||
['component', 'foo/x-foo', '--component-class', '@glimmer/component'], | ||
(_file) => { | ||
expect(_file('app/components/foo/x-foo.ts')).to.equal( | ||
glimmerComponentContents('FooXFoo') | ||
); | ||
expect(_file('app/components/foo/x-foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo/x-foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo/x-foo', | ||
componentInvocation: 'Foo::XFoo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'my-app/tests/helpers'; | ||
import { render } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
module('Integration | Component | <%= component =%>', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('it renders', async function (assert) { | ||
// Set any properties with this.set('myProperty', 'value'); | ||
// Handle any actions with this.set('myAction', function(val) { ... }); | ||
|
||
await render(hbs`<<%= componentInvocation =%> />`); | ||
|
||
assert.dom().hasText(''); | ||
|
||
// Template block usage: | ||
await render(hbs` | ||
<<%= componentInvocation =%>> | ||
template block text | ||
</<%= componentInvocation =%>> | ||
`); | ||
|
||
assert.dom().hasText('template block text'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,9 +51,10 @@ | |
"lint:eslint:fix": "npm-run-all \"lint:eslint --fix\"", | ||
"lint:fix": "npm-run-all lint:*:fix", | ||
"test": "node bin/run-tests.js", | ||
"test:blueprints:js": "EMBER_TYPESCRIPT_BLUEPRINTS=false pnpm test:blueprints:ts", | ||
"test:blueprints:ts": "mocha node-tests/blueprints/**/*-test.js", | ||
"test:blueprints": "pnpm test:blueprints:js && pnpm test:blueprints:ts", | ||
"test:blueprints:js": "EMBER_TYPESCRIPT_BLUEPRINTS=false pnpm test:blueprints:js-from-ts", | ||
"test:blueprints:js-from-ts": "mocha node-tests/blueprints/**/*-test.js", | ||
"test:blueprints:ts": "mocha node-tests/blueprints-ts/**/*-test.js", | ||
"test:blueprints": "npm-run-all test:blueprints:*", | ||
Windvis marked this conversation as resolved.
Show resolved
Hide resolved
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. We can remove this one now since we no longer use it in CI, and I don't expect anyone to run all of them like this locally either. |
||
"test:node": "qunit tests/node/**/*-test.js", | ||
"test:browserstack": "node bin/run-browserstack-tests.js", | ||
"test:wip": "vite build --mode development --minify false && testem ci", | ||
|
@@ -170,6 +171,9 @@ | |
"pnpm": { | ||
"overrides": { | ||
"rollup": "^4.2.0" | ||
}, | ||
"patchedDependencies": { | ||
"[email protected]": "patches/[email protected]" | ||
} | ||
}, | ||
"peerDependencies": { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why does js.js happen?
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.
When people add an extension when generating a component:
ember g component-class foo.js
. I just noticed when copying one of the tests and adjusting it for .ts.Other ts blueprints will have the same issue.