-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- r converted mocha namer to typescript
- Loading branch information
Showing
11 changed files
with
130 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,3 +53,4 @@ lib/Namer.js | |
lib/Scrubbers/Scrubbers.js | ||
lib/Scrubbers/DateScrubber.js | ||
/yarn.lock | ||
/lib/Providers/Mocha/**/**.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {printArray, printJson} from "../../Utilities/Printers"; | ||
/* ^^^ If the above line is failing, please add | ||
# 1. Jest Config | ||
``` | ||
"transformIgnorePatterns": ["node_modules/@3ds"] | ||
``` | ||
# 2. tsconfig.json | ||
``` | ||
"esModuleInterop": true | ||
``` | ||
*/ | ||
import {Options} from "../../Core/Options"; | ||
import {MochaNamer} from "./MochaNamer"; | ||
import mocha from 'mocha'; | ||
|
||
const StringWriter = require("../../StringWriter"); | ||
const approvals = require("../../Approvals"); | ||
let mochaTest: any = null; | ||
|
||
export function it2(label: string, test: () => void): void { | ||
mocha.it(label, function () { | ||
mochaTest = this; | ||
console.log("Mocha Test: ", mochaTest.test.name); | ||
test(); | ||
}); | ||
} | ||
|
||
export function verify(sut: any, options?: Options): void { | ||
options = options || new Options() | ||
options = options.withNamer(new MochaNamer(mochaTest.test)); | ||
const config = options.getConfig(approvals.getConfig()); | ||
const scrubbed = options.scrub(`${sut}`); | ||
const writer = new StringWriter(config, scrubbed, options.forFile().getFileExtension()); | ||
let namer = options.getNamer(); | ||
approvals.verifyWithControl(namer, writer, null, config); | ||
} | ||
|
||
export function verifyAsJson(data: any, options?: Options): void { | ||
const text = printJson(data); | ||
options = options || new Options() | ||
options = options.forFile().withFileExtention(".json") | ||
verify(text, options); | ||
} | ||
|
||
export function verifyAll<T>(header:string, list: T[], formatter?: ((element: T) => string), options?: Options): void{ | ||
const text = printArray(header, list, formatter); | ||
verify(text, options); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import path from "path"; | ||
|
||
const Namer: any = require("../../Namer"); | ||
|
||
export interface MochaTest { | ||
file: string; | ||
parent?: MochaTest; | ||
title: string; | ||
} | ||
|
||
export class MochaNamer extends Namer { | ||
private ctx: MochaTest; | ||
|
||
constructor(mochaTest: any, overrideBasePath?: string) { | ||
if (!mochaTest) { | ||
throw new Error("Mocha test context was not supplied"); | ||
} | ||
mochaTest = mochaTest.test || mochaTest; | ||
|
||
super('', ''); | ||
|
||
this.ctx = mochaTest; | ||
this.path = overrideBasePath || path.dirname(mochaTest.file); | ||
} | ||
|
||
getFullTestName(testContext: MochaTest): string { | ||
let test = testContext; | ||
|
||
let parentStack: MochaTest[] = []; | ||
let currParent: MochaTest | undefined = test; | ||
while (currParent && currParent.parent) { | ||
parentStack.push(currParent); | ||
currParent = currParent.parent; | ||
} | ||
|
||
let newTitle = ''; | ||
let parentStackReversed = parentStack.reverse(); | ||
parentStackReversed.forEach((item, index) => { | ||
if (index !== 0) { | ||
newTitle += "."; | ||
} | ||
|
||
newTitle += item.title.split(' ').join('_').replace(/[^\w\s]/gi, '_'); | ||
}); | ||
|
||
return newTitle; | ||
} | ||
|
||
pathCreator(type: string, ext: string): string { | ||
if (!this.name) { | ||
if (!this.ctx) { | ||
throw new Error("ctx was not defined."); | ||
} | ||
this.name = this.getFullTestName(this.ctx); | ||
} | ||
|
||
return super.pathCreator(type, ext); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
//require('approvals').mocha(); | ||
|
||
import {it2, verify} from "../../../../lib/Providers/Mocha/MochaApprovals"; | ||
|
||
const assert = require('assert'); | ||
// import { describe, it } from 'mocha'; | ||
|
||
describe("Mocha Typescript Approvals", () => { | ||
|
||
it("verify", () => { | ||
// verify("Hello From Approvals"); | ||
assert.equal(2, 2); | ||
}); | ||
|
||
// it2("verify approvals", () => { | ||
// verify("Hello From Approvals"); | ||
// // get the test name of the current mocha test | ||
// }); | ||
}); | ||
|
||
|