|
| 1 | +const assert = require('assert'); |
| 2 | +const locations = require('../config/locations'); |
| 3 | +const init = require('../cli/lib/init'); |
| 4 | +const fs = require('fs'); |
| 5 | + |
| 6 | +//these are needed to account for the mutation of a singleton pathing module |
| 7 | +const path = require('path'); |
| 8 | +const normalizedPath = path.normalize(__dirname); |
| 9 | + |
| 10 | +describe('configure', () => { |
| 11 | + describe('init module', () => { |
| 12 | + it('will copy file to custom dir', (done) => { |
| 13 | + init({configDir: 'foo'}, (err, file) => { |
| 14 | + assert.equal(file, 'foo/default.yaml'); |
| 15 | + |
| 16 | + const fileBuf = fs.readFileSync('config/default.yaml'); |
| 17 | + const testBuf = fs.readFileSync(file); |
| 18 | + assert.equal(fileBuf.toString(), testBuf.toString()); |
| 19 | + done(); |
| 20 | + }); |
| 21 | + }); |
| 22 | + it('will copy file to default dir', () => { |
| 23 | + init({}, (err, file) => { |
| 24 | + console.log(file); |
| 25 | + assert.equal(file, path.join(normalizedPath, 'default.yaml')); |
| 26 | + |
| 27 | + const fileBuf = fs.readFileSync('config/default.yaml'); |
| 28 | + const testBuf = fs.readFileSync(file); |
| 29 | + assert.equal(fileBuf.toString(), testBuf.toString()); |
| 30 | + done(); |
| 31 | + }); |
| 32 | + }); |
| 33 | + }); |
| 34 | + describe('locations module', () => { |
| 35 | + it('will build a source path without a configDir', () => { |
| 36 | + var configPath = locations.getSourcePath('test', 'foo'); |
| 37 | + //This path differs from the actual config path because we mutate the singleton in other tests. |
| 38 | + assert.equal(configPath, path.join(normalizedPath, 'test-foo-config.yaml')); |
| 39 | + }); |
| 40 | + it('will build a source path with a configDir', () => { |
| 41 | + var configPath = locations.getSourcePath('test', 'foo', 'foo'); |
| 42 | + assert.equal(configPath, 'foo/test-foo-config.yaml'); |
| 43 | + }); |
| 44 | + it('will build a cache path without a configDir', () => { |
| 45 | + var cachePath = locations.getCachePath('test', 'foo'); |
| 46 | + //This path differs from the actual config path because we mutate the singleton in other tests. |
| 47 | + assert.equal(cachePath, path.join(normalizedPath, 'test-foo-cache-config.yaml')); |
| 48 | + }); |
| 49 | + it('will build a cache path with a configDir', () => { |
| 50 | + var cachePath = locations.getCachePath('test', 'foo', 'foo'); |
| 51 | + assert.equal(cachePath, 'foo/test-foo-cache-config.yaml'); |
| 52 | + }); |
| 53 | + it('will put together a properly named source file', () => { |
| 54 | + var sourceFile = locations.getSourceFile('test', 'foo'); |
| 55 | + assert.equal(sourceFile, 'test-foo-config.yaml'); |
| 56 | + }); |
| 57 | + }); |
| 58 | +}); |
0 commit comments