Skip to content

Commit 9f9cc75

Browse files
Prettier
1 parent 46a0b67 commit 9f9cc75

14 files changed

+747
-15
lines changed

scripts/prune-dts/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"reportDir": "./coverage/node"
2727
},
2828
"devDependencies": {
29-
"mocha": "8.2.1"
29+
"@types/prettier": "2.1.5",
30+
"mocha": "8.2.1",
31+
"prettier": "2.1.2"
3032
}
3133
}

scripts/prune-dts/prune-dts.test.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import * as os from 'os';
1919
import * as fs from 'fs';
2020
import * as path from 'path';
21+
import { format, resolveConfig } from 'prettier';
2122
import { expect } from 'chai';
2223
import { describe, it } from 'mocha';
2324

@@ -27,13 +28,12 @@ const testCasesDir = path.resolve(__dirname, 'tests');
2728
const tmpDir = os.tmpdir();
2829

2930
const testDataFilter = /(.*).input.d.ts/;
30-
const testCaseFilterRe = /.*inherits.*/;
31+
const testCaseFilterRe = /.*/;
3132

32-
function runScript(filename: string): string {
33-
const inputFile = path.resolve(testCasesDir, filename);
33+
function runScript(inputFile: string): string {
3434
const outputFile = path.resolve(tmpDir, 'output.d.ts');
3535
pruneDts(inputFile, outputFile);
36-
return fs.readFileSync(outputFile, 'utf-8');
36+
return outputFile;
3737
}
3838

3939
interface TestCase {
@@ -67,12 +67,33 @@ function getTestCases(): TestCase[] {
6767

6868
describe('Prune DTS', () => {
6969
for (const testCase of getTestCases()) {
70-
it(testCase.name, () => {
71-
const expectedDts = fs.readFileSync(
72-
path.resolve(testCasesDir, testCase.outputFileName),
70+
it(testCase.name, async () => {
71+
const absoluteInputFile = path.resolve(
72+
testCasesDir,
73+
testCase.inputFileName
74+
);
75+
const absoluteOutputFile = path.resolve(
76+
testCasesDir,
77+
testCase.outputFileName
78+
);
79+
80+
const tmpFile = runScript(absoluteInputFile);
81+
const prettierConfig = await resolveConfig(absoluteInputFile);
82+
83+
const expectedDtsUnformatted = fs.readFileSync(
84+
absoluteOutputFile,
7385
'utf-8'
7486
);
75-
const actualDts = runScript(testCase.inputFileName);
87+
const expectedDts = format(expectedDtsUnformatted, {
88+
filepath: absoluteOutputFile,
89+
...prettierConfig
90+
});
91+
const actualDtsUnformatted = fs.readFileSync(tmpFile, 'utf-8');
92+
const actualDts = format(actualDtsUnformatted, {
93+
filepath: tmpFile,
94+
...prettierConfig
95+
});
96+
7697
expect(actualDts).to.equal(expectedDts);
7798
});
7899
}

scripts/prune-dts/prune-dts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function convertPropertiesForEnclosingClass(
227227
/* importAdder= */ undefined,
228228
(c: ts.ClassElement) => newMembers.push(c)
229229
);
230-
return [];
230+
return newMembers;
231231
}
232232
/**
233233
* Replaces input types of public APIs that consume non-exported types, which

scripts/prune-dts/tests/hide-constructor.input.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ export class Foo {
1919
/** @hideconstructor */
2020
constructor(bar: string);
2121
}
22+
23+
export {};

scripts/prune-dts/tests/hide-constructor.output.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
export class Foo {
1918
private constructor();
2019
}
20+
export {};

scripts/prune-dts/tests/inherits-non-exported-members.input.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ declare class Bar {
2121
export class Foo extends Bar {
2222
foo: string;
2323
}
24+
export {};

scripts/prune-dts/tests/inherits-non-exported-members.output.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
export class Foo {
19-
bar: string;
2018
foo: string;
19+
bar: string;
2120
}
21+
export {};

scripts/prune-dts/tests/prunes-non-exported-types.input.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ export function foo(): void;
1919
declare function bar(): void;
2020
export class Foo {}
2121
declare class Bar {}
22+
23+
export {};

scripts/prune-dts/tests/prunes-non-exported-types.output.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
export function foo(): void;
1918
export class Foo {}
19+
export {};

scripts/prune-dts/tests/prunes-underscores.input.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@
1818
export class Foo {
1919
foo: string;
2020
_bar: string;
21+
_barMethod(): string;
22+
get _barGetter(): string;
23+
readonly _barProperty: string;
2124
}
25+
26+
export {};

scripts/prune-dts/tests/prunes-underscores.output.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
export class Foo {
1918
foo: string;
2019
}
20+
export {};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
declare class Bar {}
19+
export class Foo extends Bar {}
20+
export function foo(bar: Bar): Bar;
21+
export class Foobar {
22+
constructor(bar: Bar);
23+
bar: Bar;
24+
readonly barProperty: Bar;
25+
get barGetter(): Bar;
26+
barMethod(bar: Bar): Bar;
27+
}
28+
export {};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
export class Foo {}
19+
export function foo(bar: Foo): Foo;
20+
export class Foobar {
21+
constructor(bar: Foo);
22+
bar: Foo;
23+
readonly barProperty: Foo;
24+
get barGetter(): Foo;
25+
barMethod(bar: Foo): Foo;
26+
}
27+
export {};

0 commit comments

Comments
 (0)