UNPKG

2 kBJavaScriptView Raw
1// require dependencies
2var fs = require('fs')
3var path = require('path')
4var Reporter = require('jasmine-spec-reporter')
5var Converter = require(path.resolve(__dirname, '../lib'))
6
7// register custom reporter
8var reporter = new Reporter({
9 displayStacktrace: 'none', // display stacktrace for each failed assertion, values: (all|specs|summary|none)
10 displaySuccessesSummary: true, // display summary of all successes after execution
11 displayFailuresSummary: false, // display summary of all failures after execution
12 displaySuccessfulSpec: true, // display each successful spec
13 displayFailedSpec: true // display each failed spec
14})
15
16jasmine.getEnv().clearReporters()
17jasmine.getEnv().addReporter(reporter);
18
19describe('SCSS to LESS converter', function() {
20 let fixtures, converter
21
22 function getName(file) {
23 return file.split('.')[0]
24 }
25
26 function runTest(name, fixtureFile, expectedFile) {
27 let convert = new Promise(function(resolve, reject) {
28 fs.readFile(fixtureFile, 'utf-8', function(err, data) {
29 if (err) reject(err);
30 resolve(converter.process(data, { fileInfo: { filename: fixtureFile } }))
31 })
32 })
33
34 let expected = new Promise(function(resolve, reject) {
35 fs.readFile(expectedFile, 'utf-8', function(err, data) {
36 if (err) reject(err);
37 resolve(data);
38 })
39 })
40
41 it('should convert "' + name + '"', function (done) {
42 var test = function(values) {
43 expect(values[0]).toEqual(values[1])
44 done()
45 }
46
47 var error = function(err) {
48 fail(err)
49 }
50
51 Promise.all([convert, expected]).then(test).catch(error)
52 })
53 }
54
55 // locals
56 fixtures = fs.readdirSync(path.resolve(__dirname, './fixtures'))
57
58 // create instances
59 converter = new Converter()
60
61 fixtures.map(function (file) {
62 let filename = getName(file)
63 runTest(filename, path.resolve(__dirname, './fixtures', file), path.resolve(__dirname, './expected', filename + '.less'))
64 })
65})