Skip to content

Commit 4a1c033

Browse files
committed
test: Use system temp directory rather than a custom one
1 parent 98290c0 commit 4a1c033

7 files changed

Lines changed: 18 additions & 29 deletions

File tree

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
lib/**
2-
test/fixtures/.tmp/**

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,4 @@ $RECYCLE.BIN/
129129

130130
yarn.lock
131131
package-lock.json
132-
test/fixtures/.tmp
133132
lib

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"sinon": "^3.0.0",
6565
"sr-commit-analyzer": "^2.0.2",
6666
"sr-release-notes-generator": "^1.1.2",
67-
"uuid": "^3.1.0"
67+
"tempy": "^0.1.0"
6868
},
6969
"engines": {
7070
"node": ">=4"
@@ -119,7 +119,7 @@
119119
"url": "git+https://github.com/vanduynslagerp/karma-postcss-preprocessor.git"
120120
},
121121
"scripts": {
122-
"clean": "rimraf test/fixtures/.tmp && rimraf coverage && rimraf .nyc_output",
122+
"clean": "rimraf rimraf coverage && rimraf .nyc_output",
123123
"cm": "git-cz",
124124
"codecov": "codecov",
125125
"commitmsg": "commitlint -e",

test/helpers/karma.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ const KARMA_CONFIG = {
1212
basePath: '',
1313
frameworks: ['jasmine-jquery'],
1414
preprocessors: {
15-
'test/fixtures/**/!(*custom).+(css|txt)': ['postcss'],
16-
'test/fixtures/**/basic': ['postcss'],
17-
'test/fixtures/**/*custom.+(css|txt)': ['custom_postcss'],
18-
'test/fixtures/**/*.test.js': ['babel'],
15+
'/**/!(*custom).+(css|txt)': ['postcss'],
16+
'/**/basic': ['postcss'],
17+
'/**/*custom.+(css|txt)': ['custom_postcss'],
18+
'/**/*.test.js': ['babel'],
1919
},
2020
babelPreprocessor: {options: {babelrc: false, presets: ['es2015'], sourceMap: 'inline'}},
2121
colors: true,

test/helpers/utils.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
import path from 'path';
22
import {readFile} from 'fs-extra';
3-
import uuid from 'uuid';
43
import pEvent from 'p-event';
54
import sourceMappingURL from 'source-map-url';
65
import postcss from 'postcss';
76

8-
/**
9-
* Generate a unique temporary file/directory path.
10-
*
11-
* @param {String} filename file/directory name to create under 'test/fixtures/.tmp'.
12-
* @return {String} the path of the unique temporary file/directory.
13-
*/
14-
export function tmp(filename) {
15-
return path.join('test/fixtures/.tmp', uuid(), filename || '');
16-
}
17-
187
/* eslint-disable no-magic-numbers */
198
/**
209
* Return a Promise that resolve when an event is emitted and reject after a timeout expire if the event is not emitted.

test/integration.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import path from 'path';
22
import {copy} from 'fs-extra';
33
import test from 'ava';
4+
import {stub} from 'sinon';
5+
import tempy from 'tempy';
46
import cssnano from 'cssnano';
57
import mixins from 'postcss-mixins';
68
import simpleVars from 'postcss-simple-vars';
79
import atImport from 'postcss-import';
8-
import {stub} from 'sinon';
910
import {run, watch, waitForRunComplete} from './helpers/karma';
10-
import {tmp} from './helpers/utils';
1111

1212
let stubWrite;
1313

@@ -56,7 +56,7 @@ test('Log error on invalid css file', async t => {
5656
});
5757

5858
test('Re-compile css file when dependency is modified', async t => {
59-
const dir = path.resolve(tmp());
59+
const dir = tempy.directory();
6060
const fixture = path.join(dir, 'with-partial.css');
6161
const includePath = path.join(dir, 'partials');
6262
const partial = path.join(includePath, 'partial.css');
@@ -68,6 +68,7 @@ test('Re-compile css file when dependency is modified', async t => {
6868
copy('test/fixtures/with-partial.css', fixture),
6969
]);
7070

71+
console.log(fixture.replace('fixtures', '*').replace('with', '+(with|nomatch)'), 'test/fixtures/styles.test.js');
7172
const {server, watcher} = await watch(
7273
[fixture.replace('fixtures', '*').replace('with', '+(with|nomatch)'), 'test/fixtures/styles.test.js'],
7374
{options: {plugins: [atImport({path: [includePath]}), mixins, simpleVars, cssnano]}}

test/unit.test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import path from 'path';
22
import {readFile, copy, outputFile, remove} from 'fs-extra';
33
import test from 'ava';
44
import {spy, match} from 'sinon';
5+
import tempy from 'tempy';
56
import cssnano from 'cssnano';
67
import mixins from 'postcss-mixins';
78
import simpleVars from 'postcss-simple-vars';
89
import atImport from 'postcss-import';
9-
import {tmp, waitFor, compile} from './helpers/utils';
10+
import {waitFor, compile} from './helpers/utils';
1011
import {mockPreprocessor} from './helpers/mock';
1112

1213
test('Compile css file', async t => {
@@ -227,7 +228,7 @@ test('Do not add dependency to watcher if parent is not watched', async t => {
227228
});
228229

229230
test('Add dependency to watcher only once, even when its referenced multiple times', async t => {
230-
const dir = path.resolve(tmp());
231+
const dir = tempy.directory();
231232
const fixture = path.join(dir, 'with-partial.css');
232233
const otherFixture = path.join(dir, 'other-with-partial.css');
233234
const includePath = path.join(dir, 'partials');
@@ -286,7 +287,7 @@ test('Add dependency to watcher only once if file is overwritten', async t => {
286287
});
287288

288289
test('Remove dependency from watcher if not referenced anymore', async t => {
289-
const dir = path.resolve(tmp());
290+
const dir = tempy.directory();
290291
const fixture = path.join(dir, 'with-partial.css');
291292
const includePath = path.join(dir, 'partials');
292293
const partial = path.join(includePath, 'partial.css');
@@ -322,7 +323,7 @@ test('Remove dependency from watcher if not referenced anymore', async t => {
322323
});
323324

324325
test('Do not remove dependency from watcher when unreferenced, if another file still depends on it', async t => {
325-
const dir = path.resolve(tmp());
326+
const dir = tempy.directory();
326327
const fixture = path.join(dir, 'with-partial.css');
327328
const otherFixture = path.join(dir, 'other-with-partial.css');
328329
const includePath = path.join(dir, 'partials');
@@ -363,7 +364,7 @@ test('Do not remove dependency from watcher when unreferenced, if another file s
363364
});
364365

365366
test('Do not remove dependency from watcher when different files have differents childs', async t => {
366-
const dir = path.resolve(tmp());
367+
const dir = tempy.directory();
367368
const fixture = path.join(dir, 'with-partial.css');
368369
const otherFixture = path.join(dir, 'other-with-partial.css');
369370
const includePath = path.join(dir, 'partials');
@@ -403,7 +404,7 @@ test('Do not remove dependency from watcher when different files have differents
403404
});
404405

405406
test('Call refreshFiles when dependency is modified', async t => {
406-
const dir = path.resolve(tmp());
407+
const dir = tempy.directory();
407408
const fixture = path.join(dir, 'with-partial.css');
408409
const includePath = path.join(dir, 'partials');
409410
const partial = path.join(includePath, 'partial.css');
@@ -431,7 +432,7 @@ test('Call refreshFiles when dependency is modified', async t => {
431432
});
432433

433434
test('Call refreshFiles when dependency is deleted and added', async t => {
434-
const dir = path.resolve(tmp());
435+
const dir = tempy.directory();
435436
const fixture = path.join(dir, 'with-partial.css');
436437
const includePath = path.join(dir, 'partials');
437438
const partial = path.join(includePath, 'partial.css');

0 commit comments

Comments
 (0)