UNPKG

3.31 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as events from 'events';
3import { INilCallback } from 'util.toolbox';
4export interface IPatternOpts {
5 columns?: number;
6 chevrons?: string[];
7 repeat?: number;
8}
9export interface IFixtureOpts {
10 basedir?: string;
11 dataFile?: string;
12 fixtureDirectory?: string;
13 jsonFile?: string;
14 script?: string;
15 templateData?: {
16 [name: string]: string;
17 };
18 loremIpsum?: any;
19 pattern?: IPatternOpts;
20}
21export interface IFixtureCallback extends INilCallback {
22 (err: Error | null, directories: string[] | any): void | null;
23}
24/** Creates an instance of a fixture */
25export declare class Fixture extends events.EventEmitter {
26 /**
27 * Removes all of the temporary directories that were created by fixtures
28 * in test cases. Each fixture registers the directory it created when it
29 * was instantiated. This will iterate through all of those directories and
30 * remove them. It should be called as the last step in any testing.
31 * @param [cb] {FixtureCallback} a callback function exectued when the cleanup
32 * procedure is complete. The callback parameters are:
33 *
34 * - err {Error}: error object if an error has occurred. Null if no error has
35 * occurred.
36 * - directories {string[]}: a list of the directories that were removed.
37 *
38 */
39 static cleanup(cb?: IFixtureCallback): void;
40 private _basedir;
41 private _dir;
42 private _data;
43 private _files;
44 private _loremIpsum;
45 private _name;
46 private _obj;
47 private _opts;
48 private _pattern;
49 private _src;
50 /**
51 * Creates an instance of a fixture object for use in a unit test. By
52 * default it looks lin ./test/fixtures.
53 * @param [name] {string} the name of the fixture to load
54 * @param [opts] {object} optional arguments (see README for details)
55 * @constructor
56 */
57 constructor(name?: string, opts?: IFixtureOpts);
58 /**
59 * Generates a test pattern string. The generated string is created from a
60 * list of chevrons. Each chevron is a full row of N columns. The default
61 * string is 26 rows with 80 columns, where each default chevron is A-Z
62 */
63 private patternGenerator;
64 /**
65 * Takes a file name within the fixture, and reads the contents of the
66 * file into a buffer and returns it. This is the name of the relative path
67 * and file within the fixture.
68 * @param filename {string} the name of the file within the fixture to read.
69 * @returns a string representing the contents of the requested file.
70 */
71 read(filename: string): string;
72 /**
73 * Sets the base location for the temporariy files that this Fixture instance
74 * will use.
75 * @returns {string} the path location for the base directory
76 */
77 setBaseDirectory(): string;
78 /**
79 * Returns a string representation of the internal object structure of
80 * the Fixture.
81 * @returns {string} the string representing the object.
82 */
83 toString(): string;
84 basedir: string;
85 readonly data: string[];
86 readonly dir: string;
87 readonly files: string[];
88 readonly loremIpsum: string;
89 readonly name: string;
90 readonly obj: any;
91 readonly pattern: string;
92 readonly src: string;
93}