forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3dbe19
commit 53a9675
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import runJest from '../runJest'; | ||
import {cleanup, run, writeFiles} from '../utils'; | ||
import os from 'os'; | ||
import path from 'path'; | ||
|
||
const skipOnWindows = require('skipOnWindows'); | ||
const DIR = path.resolve(os.tmpdir(), 'jest_only_changed'); | ||
const GIT = 'git -c user.name=jest_test -c [email protected]'; | ||
|
||
skipOnWindows.suite(); | ||
|
||
beforeEach(() => cleanup(DIR)); | ||
afterEach(() => cleanup(DIR)); | ||
|
||
test('run only changed files', () => { | ||
writeFiles(DIR, { | ||
'.watchmanconfig': '', | ||
'__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`, | ||
'file1.js': 'module.exports = {}', | ||
'package.json': '{}', | ||
}); | ||
let stderr; | ||
let stdout; | ||
|
||
({stdout} = runJest(DIR, ['-o'])); | ||
expect(stdout).toMatch(/Jest can only find uncommitted changed files/); | ||
|
||
run(`${GIT} init`, DIR); | ||
run(`${GIT} add .`, DIR); | ||
run(`${GIT} commit -m "first"`, DIR); | ||
|
||
({stdout} = runJest(DIR, ['-o'])); | ||
expect(stdout).toMatch('No tests found related to files'); | ||
|
||
({stderr} = runJest(DIR, ['-o', '--lastCommit'])); | ||
expect(stderr).toMatch('PASS __tests__/file1.test.js'); | ||
|
||
writeFiles(DIR, { | ||
'__tests__/file2.test.js': `require('../file2'); test('file2', () => {});`, | ||
'__tests__/file3.test.js': `require('../file3'); test('file3', () => {});`, | ||
'file2.js': 'module.exports = {}', | ||
'file3.js': `require('./file2')`, | ||
}); | ||
|
||
({stderr} = runJest(DIR, ['-o'])); | ||
|
||
expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file2.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file3.test.js'); | ||
|
||
run(`${GIT} add .`, DIR); | ||
run(`${GIT} commit -m "second"`, DIR); | ||
|
||
({stderr} = runJest(DIR, ['-o'])); | ||
expect(stdout).toMatch('No tests found related to files'); | ||
|
||
writeFiles(DIR, { | ||
'file2.js': 'module.exports = {modified: true}', | ||
}); | ||
|
||
({stderr} = runJest(DIR, ['-o'])); | ||
expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file2.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file3.test.js'); | ||
}); |