Skip to content

Commit 46a0b67

Browse files
Add to scripts folder
1 parent 587360a commit 46a0b67

11 files changed

+657
-0
lines changed

scripts/prune-dts/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@firebase/prune-dts",
3+
"version": "2.0.2",
4+
"engines": {
5+
"node": "^8.13.0 || >=10.10.0"
6+
},
7+
"description": "A script to prune non-exported types from a d.t.s.",
8+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
9+
"scripts": {
10+
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha --require ts-node/register --timeout 5000 *.test.ts"
11+
},
12+
"license": "Apache-2.0",
13+
"dependencies": {},
14+
"repository": {
15+
"directory": "scripts/prune-dts",
16+
"type": "git",
17+
"url": "https://github.com/firebase/firebase-js-sdk.git"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/firebase/firebase-js-sdk/issues"
21+
},
22+
"nyc": {
23+
"extension": [
24+
".ts"
25+
],
26+
"reportDir": "./coverage/node"
27+
},
28+
"devDependencies": {
29+
"mocha": "8.2.1"
30+
}
31+
}

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
import * as os from 'os';
19+
import * as fs from 'fs';
20+
import * as path from 'path';
21+
import { expect } from 'chai';
22+
import { describe, it } from 'mocha';
23+
24+
import { pruneDts } from './prune-dts';
25+
26+
const testCasesDir = path.resolve(__dirname, 'tests');
27+
const tmpDir = os.tmpdir();
28+
29+
const testDataFilter = /(.*).input.d.ts/;
30+
const testCaseFilterRe = /.*inherits.*/;
31+
32+
function runScript(filename: string): string {
33+
const inputFile = path.resolve(testCasesDir, filename);
34+
const outputFile = path.resolve(tmpDir, 'output.d.ts');
35+
pruneDts(inputFile, outputFile);
36+
return fs.readFileSync(outputFile, 'utf-8');
37+
}
38+
39+
interface TestCase {
40+
name: string;
41+
inputFileName: string;
42+
outputFileName: string;
43+
}
44+
45+
function getTestCases(): TestCase[] {
46+
if (
47+
!fs.existsSync(testCasesDir) ||
48+
!fs.lstatSync(testCasesDir).isDirectory()
49+
) {
50+
throw new Error(`${testCasesDir} folder does not exist`);
51+
}
52+
53+
return fs
54+
.readdirSync(testCasesDir)
55+
.filter((fileName: string) => testDataFilter.test(fileName))
56+
.filter((fileName: string) => testCaseFilterRe.test(fileName))
57+
.map((fileName: string) => {
58+
const testCaseName = fileName.match(testDataFilter)![1];
59+
60+
const inputFileName = `${testCaseName}.input.d.ts`;
61+
const outputFileName = `${testCaseName}.output.d.ts`;
62+
63+
const name = testCaseName.replace(/-/g, ' ');
64+
return { name, inputFileName, outputFileName };
65+
});
66+
}
67+
68+
describe('Prune DTS', () => {
69+
for (const testCase of getTestCases()) {
70+
it(testCase.name, () => {
71+
const expectedDts = fs.readFileSync(
72+
path.resolve(testCasesDir, testCase.outputFileName),
73+
'utf-8'
74+
);
75+
const actualDts = runScript(testCase.inputFileName);
76+
expect(actualDts).to.equal(expectedDts);
77+
});
78+
}
79+
});

0 commit comments

Comments
 (0)