|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const processJs = require('../processJs'); |
| 4 | + |
| 5 | +const fs = require('fs-extra'); |
| 6 | +const rcs = require('rcs-core'); |
| 7 | +const json = require('json-extra'); |
| 8 | +const expect = require('chai').expect; |
| 9 | + |
| 10 | +const testCwd = 'test/files/testCache'; |
| 11 | +const fixturesCwd = 'test/files/fixtures'; |
| 12 | +const resultsCwd = 'test/files/results'; |
| 13 | + |
| 14 | +describe('processJs/processJs', () => { |
| 15 | + before(() => { |
| 16 | + rcs.nameGenerator.resetCountForTests(); |
| 17 | + rcs.selectorLibrary.fillLibrary(fs.readFileSync(fixturesCwd + '/css/style.css', 'utf8')) |
| 18 | + }); |
| 19 | + |
| 20 | + afterEach(() => { |
| 21 | + fs.removeSync(testCwd); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should process js files', done => { |
| 25 | + processJs('js/main.txt', { |
| 26 | + newPath: testCwd, |
| 27 | + cwd: fixturesCwd |
| 28 | + }, err => { |
| 29 | + let newFile = fs.readFileSync(testCwd + '/js/main.txt', 'utf8'); |
| 30 | + let expectedFile = fs.readFileSync(resultsCwd + '/js/main.txt', 'utf8'); |
| 31 | + |
| 32 | + expect(err).to.not.exist; |
| 33 | + expect(newFile).to.equal(expectedFile); |
| 34 | + |
| 35 | + done(); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should process jsx files', done => { |
| 40 | + processJs('js/react.txt', { |
| 41 | + newPath: testCwd, |
| 42 | + cwd: fixturesCwd, |
| 43 | + jsx: true, |
| 44 | + }, err => { |
| 45 | + let newFile = fs.readFileSync(testCwd + '/js/react.txt', 'utf8'); |
| 46 | + let expectedFile = fs.readFileSync(resultsCwd + '/js/react.txt', 'utf8'); |
| 47 | + |
| 48 | + expect(err).to.not.exist; |
| 49 | + expect(newFile).to.equal(expectedFile); |
| 50 | + |
| 51 | + done(); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should not process jsx files', done => { |
| 56 | + processJs('js/react.txt', { |
| 57 | + newPath: testCwd, |
| 58 | + cwd: fixturesCwd, |
| 59 | + }, err => { |
| 60 | + let newFile = fs.readFileSync(testCwd + '/js/react.txt', 'utf8'); |
| 61 | + let expectedFile = fs.readFileSync(testCwd + '/js/react.txt', 'utf8'); |
| 62 | + |
| 63 | + expect(err).to.not.exist; |
| 64 | + expect(newFile).to.equal(expectedFile); |
| 65 | + |
| 66 | + done(); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should process complex files', done => { |
| 71 | + processJs('js/complex.txt', { |
| 72 | + newPath: testCwd, |
| 73 | + cwd: fixturesCwd, |
| 74 | + }, err => { |
| 75 | + let newFile = fs.readFileSync(testCwd + '/js/complex.txt', 'utf8'); |
| 76 | + let expectedFile = fs.readFileSync(testCwd + '/js/complex.txt', 'utf8'); |
| 77 | + |
| 78 | + expect(err).to.not.exist; |
| 79 | + expect(newFile).to.equal(expectedFile); |
| 80 | + |
| 81 | + done(); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should not process multiple files', done => { |
| 86 | + processJs('js/*.txt', { |
| 87 | + newPath: testCwd, |
| 88 | + cwd: fixturesCwd, |
| 89 | + jsx: true, |
| 90 | + }, err => { |
| 91 | + let newFile = fs.readFileSync(testCwd + '/js/complex.txt', 'utf8'); |
| 92 | + let newFileTwo = fs.readFileSync(testCwd + '/js/main.txt', 'utf8'); |
| 93 | + let newFileThree = fs.readFileSync(testCwd + '/js/react.txt', 'utf8'); |
| 94 | + let expectedFile = fs.readFileSync(resultsCwd + '/js/complex.txt', 'utf8'); |
| 95 | + let expectedFileTwo = fs.readFileSync(resultsCwd + '/js/main.txt', 'utf8'); |
| 96 | + let expectedFileThree = fs.readFileSync(resultsCwd + '/js/react.txt', 'utf8'); |
| 97 | + |
| 98 | + expect(err).to.not.exist; |
| 99 | + expect(newFile).to.equal(expectedFile); |
| 100 | + expect(newFileTwo).to.equal(expectedFileTwo); |
| 101 | + expect(newFileThree).to.equal(expectedFileThree); |
| 102 | + |
| 103 | + done(); |
| 104 | + }); |
| 105 | + }); |
| 106 | +}); |
0 commit comments