-
Notifications
You must be signed in to change notification settings - Fork 9
/
tests.js
97 lines (83 loc) · 2.4 KB
/
tests.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* eslint-env node, mocha */
'use strict';
const assert = require('assert');
const fs = require('fs');
const gulpWpPot = require('../');
const testHelper = require('./test-helper');
const Vinyl = require('vinyl');
const PluginError = require('plugin-error');
const es = require('event-stream');
describe('File write tests', function () {
it('should generate a file', function (done) {
const fixturePath = 'test/fixtures/empty.php';
const testFile = new Vinyl({
path: fixturePath,
contents: fs.readFileSync(fixturePath)
});
es.readArray([testFile])
.pipe(gulpWpPot())
.on('error', function (error) {
done(error);
})
.on('data', function (file) {
assert(file.isBuffer());
done();
});
});
it('should read a file correctly', function (done) {
const fixturePath = 'test/fixtures/valid-functions.php';
const testFile = new Vinyl({
path: fixturePath,
contents: fs.readFileSync(fixturePath)
});
es.readArray([testFile])
.pipe(gulpWpPot({
src: fixturePath
}))
.on('error', function (error) {
done(error);
})
.on('data', function (file) {
const potContents = file.contents.toString();
testHelper.testValidFunctions(potContents, fixturePath);
done();
});
});
});
describe('Error handling', function () {
it('should throw an error if options is not an object or undefined', function () {
assert.throws(function () {
gulpWpPot('invalid');
}, PluginError);
});
it('should emit an error if file is a stream', function (done) {
const fixturePath = 'test/fixtures/empty.php';
const testFile = new Vinyl({
path: fixturePath,
contents: fs.createReadStream(fixturePath)
});
es.readArray([testFile])
.pipe(gulpWpPot())
.on('error', function () {
done();
})
.on('end', function () {
done(new Error('Error was not fired'));
});
});
it('should emit an error if there is an error in a file', function (done) {
const fixturePath = 'test/fixtures/invalid.php';
const testFile = new Vinyl({
path: fixturePath,
contents: fs.readFileSync(fixturePath)
});
es.readArray([testFile])
.pipe(gulpWpPot())
.on('error', function () {
done();
})
.on('end', function () {
done('Error was not fired');
});
});
});