This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspec.js
65 lines (55 loc) · 2.53 KB
/
spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/////////////////////
// gulp-node-slate //
/////////////////////
// Imports
import { assertDeepStrictEqual } from 'assert-deep-strict-equal';
import assert from 'assert';
import fs from 'fs';
import stringToStream from 'string-to-stream';
import Vinyl from 'vinyl';
// Plugin
import { gulpNodeSlate } from './gulp-node-slate.js';
////////////////////////////////////////////////////////////////////////////////
describe('The gulp-node-slate plugin', () => {
it('is exported as a function', () => {
const actual = { type: typeof gulpNodeSlate };
const expected = { type: 'function' };
assertDeepStrictEqual(actual, expected);
});
it('throws an error when given a bogus configuration', () => {
const callPluginWithBogusConfig = () => gulpNodeSlate('bogus!');
const exception = { message: 'Options parameter must be an object.' };
assert.throws(callPluginWithBogusConfig, exception);
});
});
////////////////////////////////////////////////////////////////////////////////
describe('Running the gulp-node-slate plugin', () => {
const options = { source: 'api-docs/input', build: 'api-docs/output' };
const oneMinute = 60 * 1000;
const clean = () => fs.rmSync('api-docs', { recursive: true, force: true });
before(clean);
it('passes through a file in the stream', (done) => {
const mockFile = new Vinyl({ contents: stringToStream('node-slate as a gulp task!') });
const handleFileFromStream = (file) => {
assertDeepStrictEqual({ stream: file.isStream() }, { stream: true });
const chunks = [];
const handleEnd = () => {
const actual = { data: chunks.map(chunk => chunk.toString()).join('') };
const expected = { data: 'node-slate as a gulp task!' };
assertDeepStrictEqual(actual, expected, done);
};
file.contents.on('data', chunk => chunks.push(chunk));
file.contents.on('end', handleEnd);
};
const pluginStream = gulpNodeSlate(options);
pluginStream.on('data', handleFileFromStream);
pluginStream.write(mockFile);
pluginStream.end();
}).timeout(oneMinute).retries(1); //extra time in case node-slate needs to be downloaded
it('creates the API documentation web page', () => {
const webPage = options.build + '/index.html';
const actual = { page: webPage, exists: fs.existsSync(webPage) };
const expected = { page: webPage, exists: true };
assertDeepStrictEqual(actual, expected);
});
});