Skip to content

Commit

Permalink
refactor: tests (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Dec 9, 2019
1 parent 08a4d7f commit c936416
Show file tree
Hide file tree
Showing 38 changed files with 76 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -8,7 +8,7 @@ npm-debug.log*
/local
/reports
/node_modules
/test/helpers/\[special\?directory\]
/test/fixtures/\[special\?directory\]

.DS_Store
Thumbs.db
Expand Down
4 changes: 2 additions & 2 deletions globalSetup.js
Expand Up @@ -4,9 +4,9 @@ const fs = require('fs');
// eslint-disable-next-line import/no-extraneous-dependencies
const mkdirp = require('mkdirp');

const removeIllegalCharacterForWindows = require('./test/utils/removeIllegalCharacterForWindows');
const removeIllegalCharacterForWindows = require('./test/helpers/removeIllegalCharacterForWindows');

const baseDir = path.resolve(__dirname, 'test/helpers');
const baseDir = path.resolve(__dirname, 'test/fixtures');

const specialFiles = {
'[special?directory]/nested/nestedfile.txt': '',
Expand Down
46 changes: 23 additions & 23 deletions test/CopyPlugin.test.js
@@ -1,10 +1,10 @@
import path from 'path';

import { MockCompiler } from './utils/mocks';
import { run, runEmit, runChange } from './utils/run';
import { MockCompiler } from './helpers/mocks';
import { run, runEmit, runChange } from './helpers/run';

const BUILD_DIR = path.join(__dirname, 'build');
const HELPER_DIR = path.join(__dirname, 'helpers');
const FIXTURES_DIR = path.join(__dirname, 'fixtures');

describe('apply function', () => {
describe('basic', () => {
Expand Down Expand Up @@ -393,7 +393,7 @@ describe('apply function', () => {
],
})
.then((compilation) => {
const absFrom = path.join(HELPER_DIR, 'file.txt');
const absFrom = path.join(FIXTURES_DIR, 'file.txt');

expect(Array.from(compilation.fileDependencies).sort()).toEqual(
[absFrom].sort()
Expand All @@ -412,7 +412,7 @@ describe('apply function', () => {
],
})
.then((compilation) => {
const absFrom = path.join(HELPER_DIR, 'directory');
const absFrom = path.join(FIXTURES_DIR, 'directory');

expect(Array.from(compilation.contextDependencies).sort()).toEqual(
[absFrom].sort()
Expand All @@ -435,7 +435,7 @@ describe('apply function', () => {
Array.from(compilation.contextDependencies)
.map((contextDependency) => contextDependency)
.sort()
).toEqual([path.join(HELPER_DIR, 'directory')].sort());
).toEqual([path.join(FIXTURES_DIR, 'directory')].sort());
})
.then(done)
.catch(done);
Expand All @@ -452,7 +452,7 @@ describe('apply function', () => {
],
})
.then((compilation) => {
const absFrom = path.join(HELPER_DIR, 'directory');
const absFrom = path.join(FIXTURES_DIR, 'directory');

expect(compilation.contextDependencies).not.toContain(absFrom);
})
Expand All @@ -463,8 +463,8 @@ describe('apply function', () => {
it('only include files that have changed', (done) => {
runChange({
expectedAssetKeys: ['tempfile1.txt'],
newFileLoc1: path.join(HELPER_DIR, 'watch', 'tempfile1.txt'),
newFileLoc2: path.join(HELPER_DIR, 'watch', 'tempfile2.txt'),
newFileLoc1: path.join(FIXTURES_DIR, 'watch', 'tempfile1.txt'),
newFileLoc2: path.join(FIXTURES_DIR, 'watch', 'tempfile2.txt'),
patterns: [
{
from: 'tempfile1.txt',
Expand All @@ -482,13 +482,13 @@ describe('apply function', () => {
runChange({
expectedAssetKeys: ['tempfile1.txt'],
newFileLoc1: path.join(
HELPER_DIR,
FIXTURES_DIR,
'watch',
'directory',
'tempfile1.txt'
),
newFileLoc2: path.join(
HELPER_DIR,
FIXTURES_DIR,
'watch',
'directory',
'tempfile2.txt'
Expand All @@ -507,13 +507,13 @@ describe('apply function', () => {
runChange({
expectedAssetKeys: ['tempfile1.txt', 'tempfile2.txt', '.gitkeep'],
newFileLoc1: path.join(
HELPER_DIR,
FIXTURES_DIR,
'watch',
'directory',
'tempfile1.txt'
),
newFileLoc2: path.join(
HELPER_DIR,
FIXTURES_DIR,
'watch',
'directory',
'tempfile2.txt'
Expand All @@ -535,13 +535,13 @@ describe('apply function', () => {
runChange({
expectedAssetKeys: ['dest1/tempfile1.txt'],
newFileLoc1: path.join(
HELPER_DIR,
FIXTURES_DIR,
'watch',
'directory',
'tempfile1.txt'
),
newFileLoc2: path.join(
HELPER_DIR,
FIXTURES_DIR,
'watch',
'directory',
'tempfile2.txt'
Expand All @@ -562,13 +562,13 @@ describe('apply function', () => {
runChange({
expectedAssetKeys: ['dest1/tempfile1.txt', 'dest2/tempfile1.txt'],
newFileLoc1: path.join(
HELPER_DIR,
FIXTURES_DIR,
'watch',
'directory',
'tempfile1.txt'
),
newFileLoc2: path.join(
HELPER_DIR,
FIXTURES_DIR,
'watch',
'directory',
'tempfile2.txt'
Expand Down Expand Up @@ -597,12 +597,12 @@ describe('apply function', () => {
'dest2/directory/tempfile1.txt',
],
newFileLoc1: path.join(
HELPER_DIR,
FIXTURES_DIR,
'watch',
'directory',
'tempfile1.txt'
),
newFileLoc2: path.join(HELPER_DIR, 'watch', 'tempfile2.txt'),
newFileLoc2: path.join(FIXTURES_DIR, 'watch', 'tempfile2.txt'),
patterns: [
{
context: 'directory',
Expand All @@ -626,12 +626,12 @@ describe('apply function', () => {
'dest2/tempfile1.txt',
],
newFileLoc1: path.join(
HELPER_DIR,
FIXTURES_DIR,
'watch',
'directory',
'tempfile1.txt'
),
newFileLoc2: path.join(HELPER_DIR, 'watch', 'tempfile2.txt'),
newFileLoc2: path.join(FIXTURES_DIR, 'watch', 'tempfile2.txt'),
patterns: [
{
from: '**/*.txt',
Expand All @@ -651,9 +651,9 @@ describe('apply function', () => {
it('copy only changed files (multiple patterns with difference context 2)', (done) => {
runChange({
expectedAssetKeys: ['dest1/tempfile1.txt'],
newFileLoc1: path.join(HELPER_DIR, 'watch', 'tempfile1.txt'),
newFileLoc1: path.join(FIXTURES_DIR, 'watch', 'tempfile1.txt'),
newFileLoc2: path.join(
HELPER_DIR,
FIXTURES_DIR,
'watch',
'directory',
'tempfile2.txt'
Expand Down
6 changes: 3 additions & 3 deletions test/cache-option.test.js
Expand Up @@ -6,9 +6,9 @@ import cacache from 'cacache';
import findCacheDir from 'find-cache-dir';
import isGzip from 'is-gzip';

import { runEmit } from './utils/run';
import { runEmit } from './helpers/run';

const HELPER_DIR = path.join(__dirname, 'helpers');
const FIXTURES_DIR = path.join(__dirname, 'fixtures');

describe('cache option', () => {
const cacheDir = findCacheDir({ name: 'copy-webpack-plugin' });
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('cache option', () => {

it('should cache binary file', (done) => {
const from = 'file.txt.gz';
const content = fs.readFileSync(path.join(HELPER_DIR, from));
const content = fs.readFileSync(path.join(FIXTURES_DIR, from));
const expectedNewContent = zlib.gzipSync('newchanged!');

expect(isGzip(content)).toBe(true);
Expand Down
14 changes: 7 additions & 7 deletions test/context-option.test.js
@@ -1,8 +1,8 @@
import path from 'path';

import { runEmit } from './utils/run';
import { runEmit } from './helpers/run';

const HELPER_DIR = path.join(__dirname, 'helpers');
const FIXTURES_DIR = path.join(__dirname, 'fixtures');

describe('context option', () => {
it('should work when "from" is a file', (done) => {
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('context option', () => {
],
patterns: [
{
// Todo strange behavour when you use `HELPER_DIR`, need investigate for next major release
// Todo strange behavour when you use `FIXTURES_DIR`, need investigate for next major release
from: '.',
context: '[special?directory]',
},
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('context option', () => {
],
patterns: [
{
context: path.join(HELPER_DIR, 'directory'),
context: path.join(FIXTURES_DIR, 'directory'),
from: '**/*',
to: 'nested',
},
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('context option', () => {
patterns: [
{
from: 'directoryfile.txt',
context: path.join(HELPER_DIR, 'directory'),
context: path.join(FIXTURES_DIR, 'directory'),
},
],
})
Expand All @@ -192,7 +192,7 @@ describe('context option', () => {
'newdirectory/nestedfile.txt',
],
options: {
context: path.join(HELPER_DIR, 'directory'),
context: path.join(FIXTURES_DIR, 'directory'),
},
patterns: [
{
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('context option', () => {
'newdirectory/nesteddir/nestedfile.txt',
],
options: {
context: path.join(HELPER_DIR, 'dir (86)'),
context: path.join(FIXTURES_DIR, 'dir (86)'),
},
patterns: [
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/flatten-option.test.js
@@ -1,4 +1,4 @@
import { runEmit } from './utils/run';
import { runEmit } from './helpers/run';

describe('flatten option', () => {
it('should flatten a directory\'s files to a root directory when "from" is a file', (done) => {
Expand Down
2 changes: 1 addition & 1 deletion test/force-option.test.js
@@ -1,4 +1,4 @@
import { runForce } from './utils/run';
import { runForce } from './helpers/run';

describe('force option', () => {
describe('is not specified', () => {
Expand Down
22 changes: 11 additions & 11 deletions test/from-option.test.js
@@ -1,8 +1,8 @@
import path from 'path';

import { runEmit } from './utils/run';
import { runEmit } from './helpers/run';

const HELPER_DIR = path.join(__dirname, 'helpers');
const FIXTURES_DIR = path.join(__dirname, 'fixtures');

describe('from option', () => {
describe('is a file', () => {
Expand All @@ -24,7 +24,7 @@ describe('from option', () => {
expectedAssetKeys: ['file.txt'],
patterns: [
{
from: path.join(HELPER_DIR, 'file.txt'),
from: path.join(FIXTURES_DIR, 'file.txt'),
},
],
})
Expand All @@ -50,7 +50,7 @@ describe('from option', () => {
expectedAssetKeys: ['directoryfile.txt'],
patterns: [
{
from: path.join(HELPER_DIR, 'directory/directoryfile.txt'),
from: path.join(FIXTURES_DIR, 'directory/directoryfile.txt'),
},
],
})
Expand All @@ -77,7 +77,7 @@ describe('from option', () => {
expectedAssetKeys: [],
expectedWarnings: [
new Error(
`unable to locate 'nonexistent.txt' at '${HELPER_DIR}${path.sep}nonexistent.txt'`
`unable to locate 'nonexistent.txt' at '${FIXTURES_DIR}${path.sep}nonexistent.txt'`
),
],
patterns: [
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('from option', () => {
],
patterns: [
{
from: '../helpers',
from: '../fixtures',
},
],
})
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('from option', () => {
],
patterns: [
{
from: path.join(HELPER_DIR, 'directory'),
from: path.join(FIXTURES_DIR, 'directory'),
},
],
})
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('from option', () => {
expectedAssetKeys: ['deep-nested/deepnested.txt', 'nestedfile.txt'],
patterns: [
{
from: path.join(HELPER_DIR, 'directory/nested'),
from: path.join(FIXTURES_DIR, 'directory/nested'),
},
],
})
Expand All @@ -273,7 +273,7 @@ describe('from option', () => {
expectedAssetKeys: [],
expectedWarnings: [
new Error(
`unable to locate 'nonexistent' at '${HELPER_DIR}${path.sep}nonexistent'`
`unable to locate 'nonexistent' at '${FIXTURES_DIR}${path.sep}nonexistent'`
),
],
patterns: [
Expand Down Expand Up @@ -306,7 +306,7 @@ describe('from option', () => {
expectedAssetKeys: ['file.txt'],
patterns: [
{
from: path.join(HELPER_DIR, '*.txt'),
from: path.join(FIXTURES_DIR, '*.txt'),
},
],
})
Expand Down Expand Up @@ -359,7 +359,7 @@ describe('from option', () => {
],
patterns: [
{
from: path.join(HELPER_DIR, '**/*.txt'),
from: path.join(FIXTURES_DIR, '**/*.txt'),
},
],
})
Expand Down
2 changes: 1 addition & 1 deletion test/globOptions-option.test.js
@@ -1,4 +1,4 @@
import { runEmit } from './utils/run';
import { runEmit } from './helpers/run';

describe('from option', () => {
it('should move files exclude dot files', (done) => {
Expand Down
4 changes: 2 additions & 2 deletions test/utils/mocks.js → test/helpers/mocks.js
Expand Up @@ -4,12 +4,12 @@ import CachedInputFileSystem from 'enhanced-resolve/lib/CachedInputFileSystem';
import NodeJsInputFileSystem from 'enhanced-resolve/lib/NodeJsInputFileSystem';

const BUILD_DIR = path.join(__dirname, '../build');
const HELPER_DIR = path.join(__dirname, '../helpers');
const FIXTURES_DIR = path.join(__dirname, '../fixtures');

class MockCompiler {
constructor(options = {}) {
this.options = {
context: HELPER_DIR,
context: FIXTURES_DIR,
output: {
path: options.outputPath || BUILD_DIR,
},
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/ignore-option.test.js
@@ -1,4 +1,4 @@
import { runEmit } from './utils/run';
import { runEmit } from './helpers/run';

describe('ignore option', () => {
it('should ignore files when "from" is a file', (done) => {
Expand Down

0 comments on commit c936416

Please sign in to comment.