Skip to content

Commit

Permalink
test: fix broken jest-haste-map tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Dec 26, 2018
1 parent 6c33a8f commit b8f2592
Show file tree
Hide file tree
Showing 3 changed files with 281 additions and 32 deletions.
7 changes: 1 addition & 6 deletions packages/jest-haste-map/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ jest.mock('graceful-fs', () => ({
error.code = 'ENOENT';
throw error;
}),
realpath: jest.fn(path => path),
writeFileSync: jest.fn((path, data, options) => {
expect(options).toBe(require('v8').serialize ? undefined : 'utf8');
mockFs[path] = data;
Expand Down Expand Up @@ -213,16 +214,13 @@ describe('HasteMap', () => {

it('creates valid cache file paths', () => {
jest.resetModuleRegistry();
HasteMap = require('../');

expect(
HasteMap.getCacheFilePath('/', '@scoped/package', 'random-value'),
).toMatch(/^\/-scoped-package-(.*)$/);
});

it('creates different cache file paths for different roots', () => {
jest.resetModuleRegistry();
const HasteMap = require('../');
const hasteMap1 = new HasteMap(
Object.assign({}, defaultConfig, {rootDir: '/root1'}),
);
Expand All @@ -234,7 +232,6 @@ describe('HasteMap', () => {

it('creates different cache file paths for different dependency extractor cache keys', () => {
jest.resetModuleRegistry();
const HasteMap = require('../');
const dependencyExtractor = require('./dependencyExtractor');
const config = Object.assign({}, defaultConfig, {
dependencyExtractor: require.resolve('./dependencyExtractor'),
Expand All @@ -248,7 +245,6 @@ describe('HasteMap', () => {

it('creates different cache file paths for different hasteImplModulePath cache keys', () => {
jest.resetModuleRegistry();
const HasteMap = require('../');
const hasteImpl = require('./haste_impl');
hasteImpl.setCacheKey('foo');
const hasteMap1 = new HasteMap(defaultConfig);
Expand All @@ -259,7 +255,6 @@ describe('HasteMap', () => {

it('creates different cache file paths for different projects', () => {
jest.resetModuleRegistry();
const HasteMap = require('../');
const hasteMap1 = new HasteMap(
Object.assign({}, defaultConfig, {name: '@scoped/package'}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,104 @@ Array [
"watch-project",
"/root-mock",
],
Array [
"query",
"/root-mock",
Object {
"expression": Array [
"allof",
Array [
"anyof",
Array [
"dirname",
"fruits",
],
],
Array [
"allof",
Array [
"type",
"l",
],
Array [
"anyof",
Array [
"match",
"**/node_modules/*",
"wholename",
Object {
"includedotfiles": true,
},
],
Array [
"match",
"**/node_modules/@*/*",
"wholename",
Object {
"includedotfiles": true,
},
],
],
],
],
"fields": Array [
"name",
"type",
"exists",
"mtime_ms",
],
"since": undefined,
},
],
Array [
"query",
"/root-mock",
Object {
"expression": Array [
"allof",
Array [
"anyof",
Array [
"dirname",
"vegetables",
],
],
Array [
"allof",
Array [
"type",
"l",
],
Array [
"anyof",
Array [
"match",
"**/node_modules/*",
"wholename",
Object {
"includedotfiles": true,
},
],
Array [
"match",
"**/node_modules/@*/*",
"wholename",
Object {
"includedotfiles": true,
},
],
],
],
],
"fields": Array [
"name",
"type",
"exists",
"mtime_ms",
],
"since": undefined,
},
],
Array [
"query",
"/root-mock",
Expand All @@ -22,29 +120,73 @@ Array [
"allof",
Array [
"type",
"f",
"l",
],
Array [
"anyof",
Array [
"suffix",
"js",
"match",
"**/node_modules/*",
"wholename",
Object {
"includedotfiles": true,
},
],
Array [
"suffix",
"json",
"match",
"**/node_modules/@*/*",
"wholename",
Object {
"includedotfiles": true,
},
],
],
],
"fields": Array [
"name",
"type",
"exists",
"mtime_ms",
],
"glob": Array [
"**/*.js",
"**/*.json",
"since": undefined,
},
],
Array [
"query",
"/root-mock",
Object {
"expression": Array [
"anyof",
Array [
"type",
"l",
],
Array [
"allof",
Array [
"type",
"f",
],
Array [
"anyof",
Array [
"suffix",
"js",
],
Array [
"suffix",
"json",
],
],
],
],
"fields": Array [
"name",
"type",
"exists",
"mtime_ms",
],
"since": undefined,
},
],
]
Expand All @@ -67,20 +209,103 @@ Array [
"expression": Array [
"allof",
Array [
"type",
"f",
"anyof",
Array [
"dirname",
"fruits",
],
],
Array [
"allof",
Array [
"type",
"l",
],
Array [
"anyof",
Array [
"match",
"**/node_modules/*",
"wholename",
Object {
"includedotfiles": true,
},
],
Array [
"match",
"**/node_modules/@*/*",
"wholename",
Object {
"includedotfiles": true,
},
],
],
],
],
"fields": Array [
"name",
"type",
"exists",
"mtime_ms",
],
"since": undefined,
},
],
Array [
"query",
"/root-mock",
Object {
"expression": Array [
"allof",
Array [
"anyof",
Array [
"suffix",
"js",
"dirname",
"vegetables",
],
],
Array [
"allof",
Array [
"type",
"l",
],
Array [
"suffix",
"json",
"anyof",
Array [
"match",
"**/node_modules/*",
"wholename",
Object {
"includedotfiles": true,
},
],
Array [
"match",
"**/node_modules/@*/*",
"wholename",
Object {
"includedotfiles": true,
},
],
],
],
],
"fields": Array [
"name",
"type",
"exists",
"mtime_ms",
],
"since": undefined,
},
],
Array [
"query",
"/root-mock",
Object {
"expression": Array [
"allof",
Array [
"anyof",
Array [
Expand All @@ -92,18 +317,39 @@ Array [
"vegetables",
],
],
Array [
"anyof",
Array [
"type",
"l",
],
Array [
"allof",
Array [
"type",
"f",
],
Array [
"anyof",
Array [
"suffix",
"js",
],
Array [
"suffix",
"json",
],
],
],
],
],
"fields": Array [
"name",
"type",
"exists",
"mtime_ms",
],
"glob": Array [
"fruits/**/*.js",
"fruits/**/*.json",
"vegetables/**/*.js",
"vegetables/**/*.json",
],
"since": undefined,
},
],
]
Expand Down
Loading

0 comments on commit b8f2592

Please sign in to comment.