Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Add test for expression-file
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 22, 2021
1 parent b18621e commit 44d46ff
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions baselines/requireJquery.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare namespace requireJquery {
function jqeury(w: any): any;

}

4 changes: 4 additions & 0 deletions baselines/simple.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare const simple: {
test: number;
};

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"lodash": "latest",
"mocha": "^3.0.2",
"react": "latest",
"shx": "^0.3.3",
"tslint": "^5.1.0",
"webpack": "^1.13.1"
},
Expand All @@ -30,7 +31,7 @@
],
"preferGlobal": true,
"scripts": {
"test": "mocha bin/tests/test.js",
"test": "shx cp -r ./tests/fixtures/ ./bin/tests && mocha bin/tests/test.js",
"build": "tsc",
"build-browser": "tsc -p browser && webpack",
"lint": "tslint --project tsconfig.json --format stylish"
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/require-jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const jqeury = require("jquery")

exports.jqeury = jqeury;
1 change: 1 addition & 0 deletions tests/fixtures/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.test = 1
14 changes: 14 additions & 0 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const expressions: { [s: string]: any } = {
someClass: MyClass,
};

const expressionFiles: { [s: string]: any } = {
simple: path.join(__dirname, "fixtures", "simple.js"),
requireJquery: path.join(__dirname, "fixtures", "require-jquery.js"),
};

function checkDeclarationBaseline(name: string, content: string) {
const filename = path.join(__dirname, `../../baselines/${name}`);
const existing = fs.existsSync(filename) ? fs.readFileSync(filename, 'utf-8') : '<none>';
Expand All @@ -63,3 +68,12 @@ describe("Expression tests", () => {
});
}
});

describe("Expression file test", () => {
for (const key of Object.keys(expressionFiles)) {
it(`Generates the same declaration for ${key}`, () => {
const result = tsg.generateIdentifierDeclarationFile(key!, require(expressionFiles[key!]));
checkDeclarationBaseline(`${key}.d.ts`, result);
});
}
});

0 comments on commit 44d46ff

Please sign in to comment.