ava-fixture
Advanced tools
Comparing version
import test from 'ava'; | ||
import { FixtureTest } from './interfaces'; | ||
import { FixtureOptions, FixtureBaselineTest, FixtureTest } from './interfaces'; | ||
export declare const fixtureDefaultOptions: FixtureOptions; | ||
/** | ||
@@ -9,2 +10,3 @@ * Creates fixture test. | ||
*/ | ||
export declare function fixture(ava: typeof test, path: string, options: FixtureOptions): FixtureBaselineTest; | ||
export declare function fixture(ava: typeof test, path: string): FixtureTest; |
"use strict"; | ||
var path_1 = require("path"); | ||
/** | ||
* Creates fixture test. | ||
* `cwd` is set to the case directory during the test. | ||
* @param ava The ava module function (`import ava from 'ava'`). | ||
* @param path Absolute or relative path to the fixture cases parent directory. In ava@0.17, cwd for relative path is set to the project root, instead of test file location. | ||
*/ | ||
function fixture(ava, path) { | ||
var curryMatch_1 = require("./curryMatch"); | ||
exports.fixtureDefaultOptions = { | ||
casesPath: 'cases', | ||
baselinesPath: 'baselines', | ||
resultsPath: 'results' | ||
}; | ||
function fixture(ava, path, options) { | ||
function curry(testfn) { | ||
@@ -17,3 +17,15 @@ return (function (title, caseName, run) { | ||
} | ||
var fixturePath = path_1.resolve(path, caseName); | ||
var d; | ||
if (options) { | ||
d = { | ||
casePath: path_1.resolve(path, options.casesPath, caseName), | ||
baselinePath: path_1.resolve(path, options.baselinesPath, caseName), | ||
resultPath: path_1.resolve(path, options.resultsPath, caseName) | ||
}; | ||
} | ||
else { | ||
d = { | ||
casePath: path_1.resolve(path, caseName) | ||
}; | ||
} | ||
return testfn((title ? title + ' ' : '') + "(fixture: " + caseName + ")", function (t) { | ||
@@ -23,4 +35,7 @@ var result; | ||
try { | ||
process.chdir(fixturePath); | ||
result = run(t, fixturePath); | ||
if (options) { | ||
d.match = curryMatch_1.curryMatch(d.baselinePath, d.resultPath, t); | ||
} | ||
process.chdir(d.casePath); | ||
result = run(t, d); | ||
if (result && result.then) { | ||
@@ -27,0 +42,0 @@ return result.then(function (r) { |
@@ -1,3 +0,4 @@ | ||
import { fixture } from './fixture'; | ||
import { fixture, fixtureDefaultOptions } from './fixture'; | ||
export default fixture; | ||
export { fixtureDefaultOptions }; | ||
export * from './interfaces'; |
"use strict"; | ||
var fixture_1 = require("./fixture"); | ||
exports.fixtureDefaultOptions = fixture_1.fixtureDefaultOptions; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = fixture_1.fixture; | ||
//# sourceMappingURL=index.js.map |
import { Test, ContextualTestContext, ContextualCallbackTestContext, Observable } from 'ava'; | ||
export interface ContextualDiffContext { | ||
/** | ||
* Path of the case folder | ||
*/ | ||
casePath: string; | ||
} | ||
export interface ContextualBaselineDiffContext extends ContextualDiffContext { | ||
/** | ||
* Path of the case's baseline folder | ||
*/ | ||
baselinePath: string; | ||
/** | ||
* Path of the case's result folder | ||
*/ | ||
resultPath: string; | ||
/** | ||
* Check if the baseline folder and the result folder matches. | ||
* If not, error will be thrown. | ||
*/ | ||
match(): Promise<void>; | ||
} | ||
export declare type FixtureContextualBaselineTest = (t: ContextualTestContext, d: ContextualBaselineDiffContext) => PromiseLike<any> | Iterator<any> | Observable | void; | ||
export declare type FixtureContextualBaselineSerialTest = (t: ContextualTestContext, d: ContextualBaselineDiffContext) => void; | ||
export declare type FixtureContextualBaselineCallbackTest = (t: ContextualCallbackTestContext, d: ContextualBaselineDiffContext) => void; | ||
/** | ||
* The fixture text context (the callback function). | ||
*/ | ||
export declare type FixtureContextualTest = (t: ContextualTestContext, cwd: string) => PromiseLike<any> | Iterator<any> | Observable | void; | ||
export declare type FixtureContextualSerialTest = (t: ContextualTestContext, cwd: string) => void; | ||
export declare type FixtureContextualCallbackTest = (t: ContextualCallbackTestContext, cwd: string) => void; | ||
export declare type FixtureContextualTest = (t: ContextualTestContext, d: ContextualDiffContext) => PromiseLike<any> | Iterator<any> | Observable | void; | ||
export declare type FixtureContextualSerialTest = (t: ContextualTestContext, d: ContextualDiffContext) => void; | ||
export declare type FixtureContextualCallbackTest = (t: ContextualCallbackTestContext, d: ContextualDiffContext) => void; | ||
export interface BeforeRunner { | ||
@@ -17,2 +41,18 @@ (title: string, run: Test): void; | ||
} | ||
export interface FixtureContextualBaselineTestFunction { | ||
/** | ||
* Runs a fixture test. | ||
* @param title Title of the test (for display and filtering). | ||
* @param caseName Name of the test case, matching the folder under `path`. | ||
* @param run The test function. | ||
* In this function, `cwd` is the fixture case folder. | ||
*/ | ||
(title: string, caseName: string, run: FixtureContextualBaselineTest): void; | ||
/** | ||
* Runs a fixture test. | ||
* @param caseName Name of the test case, matching the folder under `path`. | ||
* @param run The test function. | ||
*/ | ||
(caseName: string, run: FixtureContextualBaselineTest): void; | ||
} | ||
export interface FixtureContextualTestFunction { | ||
@@ -34,2 +74,17 @@ /** | ||
} | ||
export interface FixtureContextualBaselineSerialTestFunction { | ||
/** | ||
* Runs a fixture test. | ||
* @param title Title of the test (for display and filtering). | ||
* @param caseName Name of the test case, matching the folder under `path`. | ||
* @param run The test function. | ||
*/ | ||
(title: string, caseName: string, run: FixtureContextualBaselineSerialTest): void; | ||
/** | ||
* Runs a fixture test. | ||
* @param caseName Name of the test case, matching the folder under `path`. | ||
* @param run The test function. | ||
*/ | ||
(caseName: string, run: FixtureContextualBaselineSerialTest): void; | ||
} | ||
export interface FixtureContextualSerialTestFunction { | ||
@@ -50,2 +105,17 @@ /** | ||
} | ||
export interface FixtureContextualBaselineCallbackTestFunction { | ||
/** | ||
* Runs a fixture test. | ||
* @param title Title of the test (for display and filtering). | ||
* @param caseName Name of the test case, matching the folder under `path`. | ||
* @param run The test function. | ||
*/ | ||
(title: string, caseName: string, run: FixtureContextualBaselineCallbackTest): void; | ||
/** | ||
* Runs a fixture test. | ||
* @param caseName Name of the test case, matching the folder under `path`. | ||
* @param run The test function. | ||
*/ | ||
(caseName: string, run: FixtureContextualBaselineCallbackTest): void; | ||
} | ||
export interface FixtureContextualCallbackTestFunction { | ||
@@ -73,2 +143,33 @@ /** | ||
} | ||
export interface FixtureOptions { | ||
/** | ||
* Path to the fixture's cases root folder. | ||
*/ | ||
casesPath: string; | ||
/** | ||
* Path to the fixture's baselines root folder. | ||
*/ | ||
baselinesPath: string; | ||
/** | ||
* Path to the fixture's results root folder. | ||
*/ | ||
resultsPath: string; | ||
} | ||
export interface FixtureBaselineTest extends FixtureContextualBaselineTestFunction { | ||
before: BeforeRunner; | ||
serial: FixtureContextualBaselineSerialTestFunction; | ||
failing: FixtureContextualBaselineCallbackTestFunction; | ||
cb: FixtureContextualBaselineCallbackTestFunction; | ||
todo(title: string): void; | ||
only(title: string, caseName: string, run: (t: ContextualTestContext, d: ContextualBaselineDiffContext) => any): void; | ||
only(caseName: string, run: (t: ContextualTestContext, d: ContextualBaselineDiffContext) => any): void; | ||
skip(title: string, caseName: string, run: (t: ContextualTestContext, d: ContextualBaselineDiffContext) => any): void; | ||
skip(caseName: string, run: (t: ContextualTestContext, d: ContextualBaselineDiffContext) => any): void; | ||
after(title: string, run: (t: ContextualTestContext) => void): void; | ||
after(run: (t: ContextualTestContext) => void): void; | ||
beforeEach(title: string, run: (t: ContextualTestContext) => void): void; | ||
beforeEach(run: (t: ContextualTestContext) => void): void; | ||
afterEach(title: string, run: (t: ContextualTestContext) => void): void; | ||
afterEach(run: (t: ContextualTestContext) => void): void; | ||
} | ||
export interface FixtureTest extends FixtureContextualTestFunction { | ||
@@ -80,6 +181,6 @@ before: BeforeRunner; | ||
todo(title: string): void; | ||
only(title: string, caseName: string, run: (t: ContextualTestContext, cwd: string) => any): void; | ||
only(caseName: string, run: (t: ContextualTestContext, cwd: string) => any): void; | ||
skip(title: string, caseName: string, run: (t: ContextualTestContext, cwd: string) => any): void; | ||
skip(caseName: string, run: (t: ContextualTestContext, cwd: string) => any): void; | ||
only(title: string, caseName: string, run: (t: ContextualTestContext, d: ContextualDiffContext) => any): void; | ||
only(caseName: string, run: (t: ContextualTestContext, d: ContextualDiffContext) => any): void; | ||
skip(title: string, caseName: string, run: (t: ContextualTestContext, d: ContextualDiffContext) => any): void; | ||
skip(caseName: string, run: (t: ContextualTestContext, d: ContextualDiffContext) => any): void; | ||
after(title: string, run: (t: ContextualTestContext) => void): void; | ||
@@ -86,0 +187,0 @@ after(run: (t: ContextualTestContext) => void): void; |
{ | ||
"name": "ava-fixture", | ||
"description": "Write fixture tests with ava", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"main": "dist/commonjs/index.js", | ||
@@ -64,5 +64,7 @@ "typings": "dist/commonjs/index.d.ts", | ||
"peerDependencies": { | ||
"aurelia-logging": "^1.2.0", | ||
"ava": ">=0.17.0" | ||
}, | ||
"devDependencies": { | ||
"@types/mkdirp": "^0.3.29", | ||
"@types/node": "^6.0.58", | ||
@@ -79,2 +81,3 @@ "aurelia-logging": "^1.2.0", | ||
"eslint-config-unional": "^0.2.3", | ||
"mkdirp": "^0.5.1", | ||
"nyc": "^10.0.0", | ||
@@ -86,3 +89,6 @@ "rimraf": "^2.5.4", | ||
"typings": "^2.1.0" | ||
}, | ||
"dependencies": { | ||
"dir-compare": "^1.3.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
37683
65.6%15
25%308
94.94%3
200%19
11.76%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added