Skip to content

Commit

Permalink
test: add catch on del
Browse files Browse the repository at this point in the history
simplify test

tweak test names
  • Loading branch information
viankakrisna committed Jul 11, 2017
1 parent 28560ba commit a3a97df
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 50 deletions.
82 changes: 82 additions & 0 deletions specs/createHash.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import test from 'tape';
import path from 'path';
import fs from '../src/utils/fs';
import createHash, { getSources, getSourceMethod } from '../src/createHash';
import findCacheDir from 'find-cache-dir';
import makedir from 'make-dir';

const testDirectory = findCacheDir({
name: 'testing-autodll-webpack-plugin',
});

const settings = {
id: 1,
env: 'development',
watch: [testDirectory],
};

const getRandomString = () => `randomString_${Math.random()}`;

test('createHash should create new hash when files in watch directory is changed', t => {
var firstHash, secondHash;
makedir(testDirectory).then(() => {
fs
.writeFileAsync(
path.join(testDirectory, getRandomString()),
getRandomString()
)
.then(() => {
firstHash = createHash(settings);
return fs.writeFileAsync(
path.join(testDirectory, getRandomString()),
getRandomString()
);
})
.then(() => {
secondHash = createHash(settings);
t.notEqual(
firstHash,
secondHash,
`hashes should not be the same:
first hash is: ${firstHash}
second hash is: ${secondHash}`
);
t.end();
});
});
});

test('getSources should create new source when files in watch directory is changed', t => {
makedir(testDirectory).then(() => {
var firstSource, secondSource;

fs
.writeFileAsync(
path.join(testDirectory, getRandomString()),
getRandomString()
)
.then(() => {
firstSource = getSources(settings.watch, getSourceMethod('content'));
return fs.writeFileAsync(
path.join(testDirectory, getRandomString()),
getRandomString()
);
})
.then(() => {
secondSource = getSources(settings.watch, getSourceMethod('content'));
t.notEqual(
firstSource,
secondSource,
`sources should not be the same:
first source is: ${firstSource}
second source is: ${secondSource}`
);
t.end();
});
});
});

test('getSourceMethod should return a function', t => {
t.equal(typeof getSourceMethod(), 'function');
t.end();
});
48 changes: 0 additions & 48 deletions specs/features.spec.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/createHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import get from 'lodash/get';
import fs from './utils/fs';
import { cacheDir } from './paths';

const getSources = (watchPaths, sourceMethod) => {
export const getSources = (watchPaths, sourceMethod) => {
const getSource = watchPath => {
try {
if (fs.existsSync(watchPath)) {
Expand All @@ -28,7 +28,7 @@ const getSources = (watchPaths, sourceMethod) => {
return watchPaths.map(getSource).join('');
};

const getSourceMethod = key => {
export const getSourceMethod = key => {
switch (key) {
case 'content':
return filePath => fs.readFileSync(filePath, 'utf-8');
Expand Down

0 comments on commit a3a97df

Please sign in to comment.