Skip to content

Commit

Permalink
test(write): remove redundant cases
Browse files Browse the repository at this point in the history
  • Loading branch information
blond committed Sep 12, 2016
1 parent f8d2674 commit 0cefe5d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 197 deletions.
44 changes: 44 additions & 0 deletions test/normalize-artifact/handle-errors.test.js
@@ -0,0 +1,44 @@
'use strict';

const test = require('ava');

const normalizeArtifact = require('../../lib/normalize-artifact');

test('should throw error if dest is not specified', t => {
t.throws(() => normalizeArtifact(), 'You should specify the dest for artifact.');
});

test('should throw error if include or patterns param is not specified', t => {
t.throws(
() => normalizeArtifact({ dest: 'dest-dir' }),
'You should specify the includes or patterns parameters for artifact.'
);
});

test('should throw error if includes param is negative patterns', t => {
t.throws(
() => normalizeArtifact({ dest: 'dest-dir', includes: '!source-dir/**' }),
'The includes parameter of artifact should not contains negative patterns.'
);
});

test('should throw error if includes has negative patterns', t => {
t.throws(
() => normalizeArtifact({ dest: 'dest-dir', includes: ['source-dir/file-1.txt', '!source-dir/file-2.txt'] }),
'The includes parameter of artifact should not contains negative patterns.'
);
});

test('should throw error if patterns param is negative patterns', t => {
t.throws(
() => normalizeArtifact({ dest: 'dest-dir', patterns: '!source-dir/**' }),
'The first pattern of artifact should not be is negative.'
);
});

test('should throw error if first pattern is negative glob', t => {
t.throws(
() => normalizeArtifact({ dest: 'dest-dir', patterns: ['!source-dir/**', 'source-dir/file-1.txt'] }),
'The first pattern of artifact should not be is negative.'
);
});
133 changes: 0 additions & 133 deletions test/write-artifact/api.test.js

This file was deleted.

31 changes: 31 additions & 0 deletions test/write-artifact/defaults.test.js
@@ -0,0 +1,31 @@
'use strict';

// Immediately invoke all dependencies,
// because of the `copy` module use `lazy-cache` (it can't work with `mock-fs`).
process.env.UNLAZY = true;

const fs = require('fs');

const test = require('ava');
const promisify = require('es6-promisify');
const mockFs = require('mock-fs');

const writeArtifact = promisify(require('../../lib/write-artifact'));
const cwd = process.cwd();

test.afterEach(() => mockFs.restore());

test('should copy artifact by default', async t => {
mockFs({
'source-dir': {
'file-1.txt': 'Hi!',
'file-2.txt': 'Hello!'
}
});

await writeArtifact({ dest: 'dest-dir', includes: ['source-dir/**'] }, { root: cwd });

const stats = fs.statSync('dest-dir');

t.true(stats.isDirectory());
});
64 changes: 0 additions & 64 deletions test/write-artifact/errors.test.js
Expand Up @@ -10,70 +10,6 @@ const cwd = process.cwd();

test.afterEach(() => mockFs.restore());

test('should throw error if dest is not specified', t => {
t.throws(writeArtifact(), 'You should specify the dest for artifact.');
});

test('should throw error if include or patterns param is not specified', t => {
mockFs({
'source-dir': {}
});

t.throws(
writeArtifact({ dest: 'dest-dir' }),
'You should specify the includes or patterns parameters for artifact.'
);
});

test('should throw error if includes param is negative patterns', t => {
mockFs({
'source-dir': {}
});

t.throws(
writeArtifact({ dest: 'dest-dir', includes: '!source-dir/**' }),
'The includes parameter of artifact should not contains negative patterns.'
);
});

test('should throw error if includes has negative patterns', t => {
mockFs({
'source-dir': {
'file-1.txt': 'Hi!',
'file-2.txt': 'Hello!'
}
});

t.throws(
writeArtifact({ dest: 'dest-dir', includes: ['source-dir/file-1.txt', '!source-dir/file-2.txt'] }),
'The includes parameter of artifact should not contains negative patterns.'
);
});

test('should throw error if patterns param is negative patterns', t => {
mockFs({
'source-dir': {}
});

t.throws(
writeArtifact({ dest: 'dest-dir', patterns: '!source-dir/**' }),
'The first pattern of artifact should not be is negative.'
);
});

test('should throw error if first pattern is negative glob', t => {
mockFs({
'source-dir': {
'file-1.txt': 'Hi!'
}
});

t.throws(
writeArtifact({ dest: 'dest-dir', patterns: ['!source-dir/**', 'source-dir/file-1.txt'] }),
'The first pattern of artifact should not be is negative.'
);
});

test('should throw error if include file does not exist', t => {
mockFs({
'source-dir': {}
Expand Down

0 comments on commit 0cefe5d

Please sign in to comment.