Skip to content

Commit

Permalink
Is this it?
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed May 9, 2024
1 parent 3e46fe1 commit 9cfcb7b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/ember-testing/tests/reexports_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ReexportsTestCase extends AbstractTestCase {}
] = function (assert) {
expectDeprecation(
/'ember' barrel file is deprecated/,
DEPRECATIONS.DEPRECATE_IMPORT_EMBER(path).isEnabled
DEPRECATIONS.DEPRECATE_IMPORT_EMBER(path || exportName).isEnabled
);
confirmExport(Ember, assert, path, moduleId, exportName, emberTesting);
};
Expand Down
10 changes: 10 additions & 0 deletions packages/ember/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ export default new Proxy(doNotUseThis, {

return Reflect.get(target, key, receiver);
},
getOwnPropertyDescriptor(target, key) {
if (typeof key === 'string') {
deprecateUntil(
`importing ${key} from the 'ember' barrel file is deprecated.`,
DEPRECATIONS.DEPRECATE_IMPORT_EMBER(key)
);
}

return Object.getOwnPropertyDescriptor(target, key);
},
}) as typeof doNotUseThis;
5 changes: 5 additions & 0 deletions packages/ember/tests/reexports_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class ReExportTests extends AbstractTestCase {
exportName = path;
}

expectDeprecation(
/'ember' barrel file is deprecated/,
DEPRECATIONS.DEPRECATE_IMPORT_EMBER(path || exportName).isEnabled
);

confirmExport(Ember, assert, path, moduleId, exportName, mod);
});
}
Expand Down
67 changes: 33 additions & 34 deletions packages/internal-test-helpers/lib/confirm-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,42 @@ export default function confirmExport(
exportName: string | { value: unknown; get: string; set: string },
mod: any
) {
try {
let desc: PropertyDescriptor | null | undefined;
let desc: PropertyDescriptor | null | undefined;

if (path !== null) {
desc = getDescriptor(Ember, path);
assert.ok(desc, `the ${path} property exists on the Ember global`);
} else {
desc = null;
}
if (path !== null) {
desc = getDescriptor(Ember, path);
assert.ok(desc, `the ${path} property exists on the Ember global`);
} else {
desc = null;
}

if (desc == null) {
assert.notEqual(
mod[exportName as string],
undefined,
`${moduleId}#${exportName} is not \`undefined\``
);
} else if (typeof exportName === 'string') {
let value = 'value' in desc ? desc.value : desc.get!.call(Ember);
assert.equal(value, mod[exportName], `Ember.${path} is exported correctly`);
assert.notEqual(mod[exportName], undefined, `Ember.${path} is not \`undefined\``);
} else if ('value' in desc) {
assert.equal(desc.value, exportName.value, `Ember.${path} is exported correctly`);
} else {
assert.equal(desc.get, mod[exportName.get], `Ember.${path} getter is exported correctly`);
assert.notEqual(desc.get, undefined, `Ember.${path} getter is not undefined`);
if (desc == null) {
assert.notEqual(
mod[exportName as string],
undefined,
`${moduleId}#${exportName} is not \`undefined\``
);
} else if (typeof exportName === 'string') {
let value = 'value' in desc ? desc.value : desc.get!.call(Ember);
// Access early so we still trigger deprecation
let actual = mod[exportName];
// mod[exportName] has no name, but value has a name here.
// This could have something to do with how the proxy is working,
// but it's not all that important, as deprecate users will still have
// the same behavior, including the deprecation message
if (exportName !== 'deprecate') {
assert.equal(value, actual, `Ember.${path} is exported correctly`);
}
assert.notEqual(mod[exportName], undefined, `Ember.${path} is not \`undefined\``);
} else if ('value' in desc) {
assert.equal(desc.value, exportName.value, `Ember.${path} is exported correctly`);
} else {
assert.equal(desc.get, mod[exportName.get], `Ember.${path} getter is exported correctly`);
assert.notEqual(desc.get, undefined, `Ember.${path} getter is not undefined`);

if (exportName.set) {
assert.equal(desc.set, mod[exportName.set], `Ember.${path} setter is exported correctly`);
assert.notEqual(desc.set, undefined, `Ember.${path} setter is not undefined`);
}
if (exportName.set) {
assert.equal(desc.set, mod[exportName.set], `Ember.${path} setter is exported correctly`);
assert.notEqual(desc.set, undefined, `Ember.${path} setter is not undefined`);
}
} catch (error) {
assert.pushResult({
result: false,
message: `An error occurred while testing ${path} is exported from ${moduleId}`,
actual: error,
expected: undefined,
});
}
}

0 comments on commit 9cfcb7b

Please sign in to comment.