From b8f25922640f1f75d65e0bccd93b623536ee43ba Mon Sep 17 00:00:00 2001 From: aleclarson Date: Tue, 25 Dec 2018 22:01:59 -0500 Subject: [PATCH] test: fix broken jest-haste-map tests --- .../src/__tests__/index.test.js | 7 +- .../__snapshots__/watchman.test.js.snap | 286 ++++++++++++++++-- .../src/crawlers/__tests__/watchman.test.js | 20 +- 3 files changed, 281 insertions(+), 32 deletions(-) diff --git a/packages/jest-haste-map/src/__tests__/index.test.js b/packages/jest-haste-map/src/__tests__/index.test.js index 79383443fff5..a712ffe59300 100644 --- a/packages/jest-haste-map/src/__tests__/index.test.js +++ b/packages/jest-haste-map/src/__tests__/index.test.js @@ -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; @@ -213,8 +214,6 @@ describe('HasteMap', () => { it('creates valid cache file paths', () => { jest.resetModuleRegistry(); - HasteMap = require('../'); - expect( HasteMap.getCacheFilePath('/', '@scoped/package', 'random-value'), ).toMatch(/^\/-scoped-package-(.*)$/); @@ -222,7 +221,6 @@ describe('HasteMap', () => { it('creates different cache file paths for different roots', () => { jest.resetModuleRegistry(); - const HasteMap = require('../'); const hasteMap1 = new HasteMap( Object.assign({}, defaultConfig, {rootDir: '/root1'}), ); @@ -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'), @@ -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); @@ -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'}), ); diff --git a/packages/jest-haste-map/src/crawlers/__tests__/__snapshots__/watchman.test.js.snap b/packages/jest-haste-map/src/crawlers/__tests__/__snapshots__/watchman.test.js.snap index bdad73b4f8a4..31bafe4d42f9 100644 --- a/packages/jest-haste-map/src/crawlers/__tests__/__snapshots__/watchman.test.js.snap +++ b/packages/jest-haste-map/src/crawlers/__tests__/__snapshots__/watchman.test.js.snap @@ -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", @@ -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, }, ], ] @@ -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 [ @@ -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, }, ], ] diff --git a/packages/jest-haste-map/src/crawlers/__tests__/watchman.test.js b/packages/jest-haste-map/src/crawlers/__tests__/watchman.test.js index a6c42b1c2c7b..24f2253cbf14 100644 --- a/packages/jest-haste-map/src/crawlers/__tests__/watchman.test.js +++ b/packages/jest-haste-map/src/crawlers/__tests__/watchman.test.js @@ -119,6 +119,7 @@ describe('watchman watch', () => { data: { clocks: new Map(), files: new Map(), + links: new Map(), }, extensions: ['js', 'json'], ignore: pearMatcher, @@ -134,7 +135,7 @@ describe('watchman watch', () => { expect(data.clocks).toEqual( createMap({ - '': 'c:fake-clock:1', + '.': 'c:fake-clock:1', }), ); @@ -171,6 +172,7 @@ describe('watchman watch', () => { data: { clocks: new Map(), files: new Map(), + links: new Map(), }, extensions: ['js', 'json', 'zip'], ignore: pearMatcher, @@ -220,13 +222,14 @@ describe('watchman watch', () => { }; const clocks = createMap({ - '': 'c:fake-clock:1', + '.': 'c:fake-clock:1', }); return watchmanCrawl({ data: { clocks, files: mockFiles, + links: new Map(), }, extensions: ['js', 'json'], ignore: pearMatcher, @@ -238,7 +241,7 @@ describe('watchman watch', () => { expect(data.clocks).toEqual( createMap({ - '': 'c:fake-clock:2', + '.': 'c:fake-clock:2', }), ); @@ -295,13 +298,14 @@ describe('watchman watch', () => { mockFiles.set(TOMATO_RELATIVE, mockTomatoMetadata); const clocks = createMap({ - '': 'c:fake-clock:1', + '.': 'c:fake-clock:1', }); return watchmanCrawl({ data: { clocks, files: mockFiles, + links: new Map(), }, extensions: ['js', 'json'], ignore: pearMatcher, @@ -313,7 +317,7 @@ describe('watchman watch', () => { expect(data.clocks).toEqual( createMap({ - '': 'c:fake-clock:3', + '.': 'c:fake-clock:3', }), ); @@ -387,6 +391,7 @@ describe('watchman watch', () => { data: { clocks, files: mockFiles, + links: new Map(), }, extensions: ['js', 'json'], ignore: pearMatcher, @@ -443,6 +448,7 @@ describe('watchman watch', () => { data: { clocks: new Map(), files: new Map(), + links: new Map(), }, extensions: ['js', 'json'], ignore: pearMatcher, @@ -458,7 +464,7 @@ describe('watchman watch', () => { expect(data.clocks).toEqual( createMap({ - '': 'c:fake-clock:1', + '.': 'c:fake-clock:1', }), ); @@ -495,6 +501,7 @@ describe('watchman watch', () => { data: { clocks: new Map(), files: new Map(), + links: new Map(), }, extensions: ['js', 'json'], rootDir: ROOT_MOCK, @@ -535,6 +542,7 @@ describe('watchman watch', () => { data: { clocks: new Map(), files: new Map(), + links: new Map(), }, extensions: ['js', 'json'], rootDir: ROOT_MOCK,