|
1 | 1 | import * as fs from 'fs-extra';
|
| 2 | +import * as path from 'path'; |
2 | 3 | import { hook } from 'capture-console';
|
3 | 4 | import ember from 'ember-cli-blueprint-test-helpers/lib/helpers/ember';
|
4 | 5 | import blueprintHelpers from 'ember-cli-blueprint-test-helpers/helpers';
|
@@ -109,10 +110,57 @@ describe('Acceptance: ts:precompile command', function () {
|
109 | 110 | pkg.name = '@foo/my-addon'; // addon `name` is `my-addon`
|
110 | 111 | fs.writeJSONSync('package.json', pkg);
|
111 | 112 |
|
| 113 | + // CAUTION! HACKY CODE AHEAD! |
| 114 | + // The ember blueprint helper stays in the same node process, so require |
| 115 | + // keeps any previously read files cached. We need to clear out these |
| 116 | + // caches so it picks up the changes properly. |
| 117 | + delete require.cache[path.join(process.cwd(), 'index.js')]; |
| 118 | + delete require.cache[path.join(process.cwd(), 'package.json')]; |
| 119 | + |
112 | 120 | return ember(['ts:precompile']).then(() => {
|
113 | 121 | const declaration = file('test-support/test-file.d.ts');
|
114 | 122 | expect(declaration).to.exist;
|
115 | 123 | expect(declaration.content.trim()).to.equal(`export declare const testString: string;`);
|
116 | 124 | });
|
117 | 125 | });
|
| 126 | + |
| 127 | + it('generates .d.ts files for components when addon and moduleName do not match', function () { |
| 128 | + fs.ensureDirSync('addon/components'); |
| 129 | + fs.writeFileSync( |
| 130 | + 'addon/components/my-component.ts', |
| 131 | + `export const testString: string = 'hello';` |
| 132 | + ); |
| 133 | + fs.ensureDirSync('addon-test-support'); |
| 134 | + fs.writeFileSync( |
| 135 | + 'addon-test-support/test-file.ts', |
| 136 | + `export const anotherTestString: string = 'hello';` |
| 137 | + ); |
| 138 | + fs.writeFileSync( |
| 139 | + 'index.js', |
| 140 | + `module.exports = { name: '@foo/my-addon', moduleName() { return 'my-addon'; } };` |
| 141 | + ); |
| 142 | + |
| 143 | + const pkg = fs.readJSONSync('package.json'); |
| 144 | + pkg.name = '@foo/my-addon'; // addon `moduleName()` is `my-addon` |
| 145 | + fs.writeJSONSync('package.json', pkg); |
| 146 | + |
| 147 | + // CAUTION! HACKY CODE AHEAD! |
| 148 | + // The ember blueprint helper stays in the same node process, so require |
| 149 | + // keeps any previously read files cached. We need to clear out these |
| 150 | + // caches so it picks up the changes properly. |
| 151 | + delete require.cache[path.join(process.cwd(), 'index.js')]; |
| 152 | + delete require.cache[path.join(process.cwd(), 'package.json')]; |
| 153 | + |
| 154 | + return ember(['ts:precompile']).then(() => { |
| 155 | + const componentDecl = file('components/my-component.d.ts'); |
| 156 | + expect(componentDecl).to.exist; |
| 157 | + expect(componentDecl.content.trim()).to.equal(`export declare const testString: string;`); |
| 158 | + |
| 159 | + const testSupportDecl = file('test-support/test-file.d.ts'); |
| 160 | + expect(testSupportDecl).to.exist; |
| 161 | + expect(testSupportDecl.content.trim()).to.equal( |
| 162 | + `export declare const anotherTestString: string;` |
| 163 | + ); |
| 164 | + }); |
| 165 | + }); |
118 | 166 | });
|
0 commit comments