Skip to content

Commit d5a3b23

Browse files
authored
🤖 Merge PR DefinitelyTyped#74119 Add karma-html2js-preprocessor types by @niksy
1 parent b905d39 commit d5a3b23

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import "karma";
2+
3+
declare module "karma" {
4+
interface ConfigOptions {
5+
/**
6+
* see {@link https://github.com/karma-runner/karma-html2js-preprocessor#configuration}
7+
*/
8+
html2JsPreprocessor?: HTML2JSPreprocessorOptions | undefined;
9+
}
10+
11+
interface HTML2JSPreprocessorOptions {
12+
/**
13+
* Strip this from the file path
14+
*
15+
* @default ''
16+
*/
17+
stripPrefix?: string | undefined;
18+
19+
/**
20+
* Prepend this to the file path
21+
*
22+
* @default ''
23+
*/
24+
prependPrefix?: string | undefined;
25+
26+
/**
27+
* Define a custom transform function
28+
*/
29+
processPath?: (filePath: string) => string;
30+
}
31+
}
32+
33+
declare global {
34+
interface Window {
35+
/**
36+
* Collection of HTML files converted into JS strings by karma-html2js-preprocessor.
37+
*/
38+
__html__: Record<string, string>;
39+
}
40+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import karma = require("karma");
2+
3+
// Mocha reporter options tests
4+
const mochaReporter: karma.HTML2JSPreprocessorOptions = {
5+
stripPrefix: "strip",
6+
prependPrefix: "prepend",
7+
processPath: (filePath) => filePath,
8+
};
9+
10+
module.exports = (config: karma.Config) => {
11+
config.set({
12+
preprocessors: {
13+
"**/*.json": ["json"],
14+
},
15+
files: ["**/*.js", "**/*.json"],
16+
html2JsPreprocessor: {
17+
stripPrefix: "strip",
18+
prependPrefix: "$json",
19+
processPath: (filePath) => filePath,
20+
},
21+
});
22+
};
23+
24+
window.__html__["fixture"];
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"private": true,
3+
"name": "@types/karma-html2js-preprocessor",
4+
"version": "1.1.9999",
5+
"projects": [
6+
"https://github.com/karma-runner/karma-html2js-preprocessor#readme"
7+
],
8+
"dependencies": {
9+
"@types/karma": "*"
10+
},
11+
"devDependencies": {
12+
"@types/karma-html2js-preprocessor": "workspace:."
13+
},
14+
"owners": [
15+
{
16+
"name": "Ivan Nikolić",
17+
"githubUsername": "niksy"
18+
}
19+
]
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"module": "node16",
4+
"lib": [
5+
"es6",
6+
"dom"
7+
],
8+
"noImplicitAny": true,
9+
"noImplicitThis": true,
10+
"strictFunctionTypes": true,
11+
"strictNullChecks": true,
12+
"types": [],
13+
"noEmit": true,
14+
"forceConsistentCasingInFileNames": true
15+
},
16+
"files": [
17+
"index.d.ts",
18+
"karma-html2js-preprocessor-tests.ts"
19+
]
20+
}

0 commit comments

Comments
 (0)