1 | var chai = require('chai'); |
||
2 | var sinonChai = require('sinon-chai') |
||
3 | var expect = chai.expect |
||
4 | chai.use(sinonChai) |
||
5 | var mkdirp = require('mkdirp'); |
||
6 | var sinon = require('sinon'); |
||
7 | var path = require('path'); |
||
8 | var fse = require('fs-extra'); |
||
9 | |||
10 | var config = require('../../../src/cli').config |
||
11 | config.set({root: path.join(process.cwd(), 'test','fixtures')}) |
||
12 | |||
13 | var abeExtend = require('../../../src/cli').abeExtend |
||
14 | var cmsData = require('../../../src/cli').cmsData |
||
15 | var Manager = require('../../../src/cli').Manager |
||
16 | var coreUtils = require('../../../src/cli').coreUtils |
||
17 | var cmsOperations = require('../../../src/cli').cmsOperations |
||
18 | var cmsTemplates = require('../../../src/cli').cmsTemplates |
||
19 | var Manager = require('../../../src/cli').Manager; |
||
0 ignored issues
–
show
|
|||
20 | var Page = require('../../../src/cli').Page; |
||
21 | |||
22 | describe('cmsOperations', function() { |
||
23 | before( function(done) { |
||
24 | Manager.instance.init() |
||
25 | .then(function () { |
||
26 | Manager.instance._whereKeys = ['title', 'priority', 'abe_meta', 'articles'] |
||
27 | Manager.instance.updateList() |
||
28 | |||
29 | this.fixture = { |
||
30 | htmlArticle: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'article.html'), 'utf8'), |
||
31 | jsonArticle: fse.readJsonSync(path.join(process.cwd(), 'test', 'fixtures', 'files', 'article-2.json')), |
||
32 | jsonHomepage: fse.readJsonSync(path.join(process.cwd(), 'test', 'fixtures', 'data', 'homepage-1.json')) |
||
33 | } |
||
34 | done() |
||
35 | |||
36 | }.bind(this)) |
||
37 | }); |
||
38 | |||
39 | /** |
||
40 | * cmsOperations.save.saveJson |
||
41 | * |
||
42 | */ |
||
43 | it('cmsOperations.save.saveJson()', function() { |
||
44 | // stub |
||
45 | var s = sinon.sandbox.create(); |
||
46 | s.stub(fse, 'writeJsonSync', function () { return null; }.bind(this)); |
||
0 ignored issues
–
show
|
|||
47 | // s.stub(xss, 'exist', function () { return null; }.bind(this)); |
||
48 | |||
49 | var res = cmsOperations.save.saveJson('test.json', {}) |
||
50 | chai.expect(res).to.be.equal(true); |
||
51 | |||
52 | fse.writeJsonSync.restore() |
||
53 | }); |
||
54 | |||
55 | /** |
||
56 | * cmsOperations.save.saveHtml |
||
57 | * |
||
58 | */ |
||
59 | it('cmsOperations.save.saveHtml()', function() { |
||
60 | // stub |
||
61 | var s = sinon.sandbox.create(); |
||
62 | s.stub(fse, 'writeFileSync', function () { return null; }.bind(this)); |
||
0 ignored issues
–
show
|
|||
63 | s.stub(mkdirp, 'sync', function () { return null; }.bind(this)); |
||
0 ignored issues
–
show
|
|||
64 | |||
65 | var res = cmsOperations.save.saveHtml('test.json', {}) |
||
66 | chai.expect(res).to.be.equal(true); |
||
67 | |||
68 | fse.writeFileSync.restore() |
||
69 | mkdirp.sync.restore() |
||
70 | }); |
||
71 | }); |
||
72 |
This check looks for variables that are declared in multiple lines. There may be several reasons for this.
In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.
If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.