Passed
Push — master ( af7af9...a855fd )
by Rasmus
03:53 queued 01:25
created

test/tests.js   A

Complexity

Total Complexity 16
Complexity/F 1

Size

Lines of Code 96
Function Count 16

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 62
dl 0
loc 96
rs 10
c 0
b 0
f 0
wmc 16
mnd 0
bc 0
fnc 16
bpm 0
cpm 1
noi 0
1
/* eslint-env node, mocha */
2
'use strict';
3
4
const assert = require('assert');
5
const fs = require('fs');
6
const gulpWpPot = require('../');
7
const testHelper = require('./test-helper');
8
const Vinyl = require('vinyl');
9
const PluginError = require('plugin-error');
10
const es = require('event-stream');
11
12
describe('File write tests', function () {
13
  it('should generate a file', function (done) {
14
    const fixturePath = 'test/fixtures/empty.php';
15
16
    const testFile = new Vinyl({
17
      path: fixturePath,
18
      contents: fs.readFileSync(fixturePath)
19
    });
20
21
    es.readArray([testFile])
22
      .pipe(gulpWpPot())
23
      .on('error', function (error) {
24
        done(error);
25
      })
26
      .on('data', function (file) {
27
        assert(file.isBuffer());
28
        done();
29
      });
30
  });
31
32
  it('should read a file correctly', function (done) {
33
    const fixturePath = 'test/fixtures/valid-functions.php';
34
35
    const testFile = new Vinyl({
36
      path: fixturePath,
37
      contents: fs.readFileSync(fixturePath)
38
    });
39
40
    es.readArray([testFile])
41
      .pipe(gulpWpPot({
42
        src: fixturePath
43
      }))
44
      .on('error', function (error) {
45
        done(error);
46
      })
47
      .on('data', function (file) {
48
        const potContents = file.contents.toString();
49
        testHelper.testValidFunctions(potContents, fixturePath);
50
        done();
51
      });
52
  });
53
});
54
55
describe('Error handling', function () {
56
  it('should throw an error if options is not an object or undefined', function () {
57
    assert.throws(function () {
58
      gulpWpPot('invalid');
59
    }, PluginError);
60
  });
61
62
  it('should emit an error if file is a stream', function (done) {
63
    const fixturePath = 'test/fixtures/empty.php';
64
65
    const testFile = new Vinyl({
66
      path: fixturePath,
67
      contents: fs.createReadStream(fixturePath)
68
    });
69
70
    es.readArray([testFile])
71
      .pipe(gulpWpPot())
72
      .on('error', function () {
73
        done();
74
      })
75
      .on('end', function () {
76
        done(new Error('Error was not fired'));
77
      });
78
  });
79
80
  it('should emit an error if there is an error in a file', function (done) {
81
    const fixturePath = 'test/fixtures/invalid.php';
82
83
    const testFile = new Vinyl({
84
      path: fixturePath,
85
      contents: fs.readFileSync(fixturePath)
86
    });
87
88
    es.readArray([testFile])
89
      .pipe(gulpWpPot())
90
      .on('error', function () {
91
        done();
92
      })
93
      .on('end', function () {
94
        done('Error was not fired');
95
      });
96
  });
97
});
98