Skip to content

Commit

Permalink
gah, windows :(
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Dec 18, 2018
1 parent dadd03e commit c3c8e83
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions packages/jest-runtime/src/__tests__/script_transformer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@

'use strict';

const slash = require('slash');

jest
.mock('fs', () =>
// Node 10.5.x compatibility
Object.assign({}, jest.genMockFromModule('fs'), {
ReadStream: jest.requireActual('fs').ReadStream,
WriteStream: jest.requireActual('fs').WriteStream,
readFileSync: jest.fn((path, options) => {
const normalizedPath = require('slash')(path);
if (mockFs[normalizedPath]) {
return mockFs[normalizedPath];
if (mockFs[path]) {
return mockFs[path];
}

throw new Error(`Cannot read path '${normalizedPath}'.`);
throw new Error(`Cannot read path '${path}'.`);
}),
statSync: path => ({
isFile: () => !!mockFs[path],
Expand All @@ -39,7 +36,8 @@ jest
util.createDirectory = jest.fn();
return util;
})
.mock('vm');
.mock('vm')
.mock('path', () => jest.requireActual('path').posix);

jest.mock(
'test_preprocessor',
Expand Down Expand Up @@ -138,8 +136,7 @@ let writeFileAtomic;

jest.mock('write-file-atomic', () => ({
sync: jest.fn().mockImplementation((filePath, data) => {
const normalizedPath = require('slash')(filePath);
mockFs[normalizedPath] = data;
mockFs[filePath] = data;
}),
}));

Expand Down Expand Up @@ -167,18 +164,15 @@ describe('ScriptTransformer', () => {
fs = require('graceful-fs');
fs.readFileSync = jest.fn((path, options) => {
expect(options).toBe('utf8');
const normalizedPath = slash(path);

if (mockFs[normalizedPath]) {
return mockFs[normalizedPath];
if (mockFs[path]) {
return mockFs[path];
}

throw new Error(`Cannot read path '${normalizedPath}'.`);
throw new Error(`Cannot read path '${path}'.`);
});
fs.writeFileSync = jest.fn((path, data, options) => {
expect(options).toBe('utf8');
const normalizedPath = slash(path);
mockFs[normalizedPath] = data;
mockFs[path] = data;
});

fs.unlinkSync = jest.fn();
Expand Down

0 comments on commit c3c8e83

Please sign in to comment.