Skip to content

Commit

Permalink
Merge pull request #1135 from NullVoxPopuli/fixed-cached-decorator-ex…
Browse files Browse the repository at this point in the history
…port

Fix @cached decorator export from fake @glimmer/tracking module
  • Loading branch information
ef4 authored Feb 27, 2022
2 parents e9bbbad + d57cadc commit 648d38f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/compat/src/compat-adapters/@glimmer/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ class RedirectToEmber extends Plugin {
build() {
if (!this.didBuild) {
copyFileSync(join(this.inputPaths[0], 'package.json'), join(this.outputPath, 'package.json'));
outputFileSync(join(this.outputPath, 'index.js'), `export { tracked } from '@ember/-internals/metal';`);
outputFileSync(
join(this.outputPath, 'primitives', 'cache.js'),
join(this.outputPath, 'index.js'),
// Prior to ember-source 4.1, cached didn't exist
// using this way of importing from metal, cached will be undefined if pre 4.1
`import * as metal from "@ember/-internals/metal";
const { cached, createCache, getValue, isConst } = metal;
export { cached, createCache, getValue, isConst };
`
const { cached, tracked } = metal;
export { cached, tracked };`
);
outputFileSync(
join(this.outputPath, 'primitives', 'cache.js'),
`export { createCache, getValue, isConst } from "@ember/-internals/metal";`
);
this.didBuild = true;
}
Expand Down
62 changes: 62 additions & 0 deletions tests/scenarios/glimmer-tracking-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { appScenarios } from './scenarios';
import { PreparedApp } from 'scenario-tester';
import QUnit from 'qunit';
import merge from 'lodash/merge';
const { module: Qmodule, test } = QUnit;

appScenarios
.only('release')
.map('transform @glimmer/tracking', project => {
merge(project.files, {
app: {
components: {
'demo.js': `
import Component from '@glimmer/component';
import { cached } from '@glimmer/tracking';
export default class Demo extends Component {
@cached
get foo() {
return 'boop';
}
}
`,
'demo.hbs': `{{this.foo}}`,
},
},
tests: {
rendering: {
'demo-test.js': `
import { module, test } from 'qunit';
import { render } from '@ember/test-helpers';
import { setupRenderingTest } from 'ember-qunit';
import { hbs } from 'ember-cli-htmlbars';
module('<Demo>', function(hooks) {
setupRenderingTest(hooks);
test(\`doesn't error\`, async function(assert) {
await render(hbs\`<Demo />\`);
assert.dom().hasText('boop');
});
});
`,
},
},
});
})
.forEachScenario(scenario => {
Qmodule(scenario.name, function (hooks) {
let app: PreparedApp;
hooks.before(async () => {
app = await scenario.prepare();
});

test(`yarn test`, async function (assert) {
let result = await app.execute('yarn test');
assert.equal(result.exitCode, 0, result.output);
});
});
});

0 comments on commit 648d38f

Please sign in to comment.