-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Designory/tests/create-initial-tests
Creates initial tests
- Loading branch information
Showing
31 changed files
with
924 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
new |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
old |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { readdirSync, statSync } = require('fs'); | ||
const { basename, join, relative } = require('path'); | ||
|
||
const getListOfDirectories = path => readdirSync(path).filter(f => statSync(join(path, f)).isDirectory()); | ||
const relative_path = relative(process.cwd(), __dirname); | ||
|
||
const test_directories = getListOfDirectories(relative_path); | ||
const PATHS_LOOKUP = {}; | ||
test_directories.forEach(dir => (PATHS_LOOKUP[dir] = { old_dir: join(relative_path, dir, 'old'), new_dir: join(relative_path, dir, 'new') })); | ||
|
||
/** | ||
* Exports an object with keys that match all directories immediately | ||
* within this 'folders-to-compare' directory. The values on this object | ||
* are also objects with an `old_dir` and `new_dir` key, that are relative (to | ||
* this directory) paths to the 'old' and 'new directories. | ||
* | ||
* This is a bit overkill but the idea is that I can destructure these | ||
* within my tests and pass that to `diffDirectories`. | ||
* | ||
* @example PATHS_LOOKUP = { 'no-change': { old_dir: 'folders-to-compare/no-change/old', new_dir: 'folders-to-compare/no-change/new' } } | ||
*/ | ||
module.exports = PATHS_LOOKUP; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
const assert = require('assert'); | ||
const diffDirectories = require('../src/gen-diff-object'); | ||
const DEFAULT_BLACKLIST = require('../src/diff-blacklist'); | ||
|
||
// Ensure tests are run on mac operating system | ||
if (process.platform !== 'darwin') { | ||
console.error('Tests are only supported on macOS at this time'); | ||
process.exit(1); | ||
} | ||
|
||
const PATHS_LOOKUP = require('./folders-to-compare/paths-lookup'); | ||
|
||
const FILES_ADDED = 'filesAdded'; | ||
const FILES_DELETED = 'filesDeleted'; | ||
const FILES_UPDATED = 'filesUpdated'; | ||
const RESULTS_KEYS = [FILES_ADDED, FILES_DELETED, FILES_UPDATED]; | ||
|
||
describe('`diffDirectories` method', function() { | ||
it('should return three keys: `filesAdded`, `filesDeleted`, and `filesUpdated`', function(done) { | ||
let { old_dir, new_dir } = PATHS_LOOKUP['no-change']; | ||
|
||
diffDirectories(old_dir, new_dir, { log: false }) | ||
.then(result => { | ||
let keys = Object.keys(result); | ||
keys.sort(); | ||
|
||
assert.deepEqual(keys, RESULTS_KEYS); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
it('should return empty arrays when no differences are found', function(done) { | ||
let { old_dir, new_dir } = PATHS_LOOKUP['no-change']; | ||
|
||
diffDirectories(old_dir, new_dir, { log: false }) | ||
.then(result => { | ||
RESULTS_KEYS.forEach(key => { | ||
assert.strictEqual(result[key].length, 0); | ||
}); | ||
|
||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
it('should find new files', function(done) { | ||
let { old_dir, new_dir } = PATHS_LOOKUP['new-file']; | ||
|
||
diffDirectories(old_dir, new_dir, { log: false }) | ||
.then(result => { | ||
assert.strictEqual(result[FILES_ADDED].length, 1); | ||
assert.strictEqual(result[FILES_DELETED].length, 0); | ||
assert.strictEqual(result[FILES_UPDATED].length, 0); | ||
|
||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
it('should find new folders', function(done) { | ||
let { old_dir, new_dir } = PATHS_LOOKUP['new-folder']; | ||
|
||
diffDirectories(old_dir, new_dir, { log: false }) | ||
.then(result => { | ||
assert.strictEqual(result[FILES_ADDED].length, 1); | ||
assert.strictEqual(result[FILES_DELETED].length, 0); | ||
assert.strictEqual(result[FILES_UPDATED].length, 0); | ||
|
||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
// @todo Remove this test once we _do_ return all files within new folders | ||
it('should find new folders but not report all new files within that new folder', function(done) { | ||
let { old_dir, new_dir } = PATHS_LOOKUP['new-folder-with-many-new-files']; | ||
|
||
diffDirectories(old_dir, new_dir, { log: false }) | ||
.then(result => { | ||
// New folder contains 3 files, but just gets reported as one new folder | ||
assert.strictEqual(result[FILES_ADDED].length, 1); | ||
assert.strictEqual(result[FILES_DELETED].length, 0); | ||
assert.strictEqual(result[FILES_UPDATED].length, 0); | ||
|
||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
it('should find updated files', function(done) { | ||
let { old_dir, new_dir } = PATHS_LOOKUP['updated-file']; | ||
|
||
diffDirectories(old_dir, new_dir, { log: false }) | ||
.then(result => { | ||
assert.strictEqual(result[FILES_ADDED].length, 0); | ||
assert.strictEqual(result[FILES_DELETED].length, 0); | ||
assert.strictEqual(result[FILES_UPDATED].length, 1); | ||
|
||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
it('should find deleted files', function(done) { | ||
let { old_dir, new_dir } = PATHS_LOOKUP['deleted-file']; | ||
|
||
diffDirectories(old_dir, new_dir, { log: false }) | ||
.then(result => { | ||
assert.strictEqual(result[FILES_ADDED].length, 0); | ||
assert.strictEqual(result[FILES_DELETED].length, 1); | ||
assert.strictEqual(result[FILES_UPDATED].length, 0); | ||
|
||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
it('should handle new/updated/deleted all at once', function(done) { | ||
let { old_dir, new_dir } = PATHS_LOOKUP['all-combinations']; | ||
|
||
diffDirectories(old_dir, new_dir, { log: false }) | ||
.then(result => { | ||
// 1 new file + 1 new folder | ||
assert.strictEqual(result[FILES_ADDED].length, 2); | ||
assert.strictEqual(result[FILES_DELETED].length, 1); | ||
assert.strictEqual(result[FILES_UPDATED].length, 1); | ||
|
||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
// @todo support regex/globs instead of exact matches | ||
it('should ignore updated files on blacklist', function(done) { | ||
let { old_dir, new_dir } = PATHS_LOOKUP['blacklist-file']; | ||
|
||
diffDirectories(old_dir, new_dir, { log: false }) | ||
.then(result => { | ||
assert.strictEqual(result[FILES_ADDED].length, 0); | ||
assert.strictEqual(result[FILES_DELETED].length, 0); | ||
assert.strictEqual(result[FILES_UPDATED].length, 1); | ||
}) | ||
.then(() => | ||
// Run diff again, but ignore 'file.txt' | ||
diffDirectories(old_dir, new_dir, { log: false, blacklist: [...DEFAULT_BLACKLIST, 'file.txt'] }) | ||
) | ||
.then(result => { | ||
// With blacklist, we shouldn't have any diffs | ||
assert.strictEqual(result[FILES_ADDED].length, 0); | ||
assert.strictEqual(result[FILES_DELETED].length, 0); | ||
assert.strictEqual(result[FILES_UPDATED].length, 0); | ||
|
||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
}); |
Oops, something went wrong.