forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform-test.js
107 lines (91 loc) · 3.28 KB
/
transform-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* 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';
const {linkJestPackage, run} = require('../utils');
const path = require('path');
const runJest = require('../runJest');
const skipOnWindows = require('skipOnWindows');
describe('babel-jest', () => {
skipOnWindows.suite();
const dir = path.resolve(__dirname, '..', 'transform/babel-jest');
beforeEach(() => {
if (process.platform !== 'win32') {
run('npm install', dir);
linkJestPackage('babel-jest', dir);
}
});
it('runs transpiled code', () => {
// --no-cache because babel can cache stuff and result in false green
const {json} = runJest.json(dir, ['--no-cache']);
expect(json.success).toBe(true);
expect(json.numTotalTests).toBeGreaterThanOrEqual(1);
});
it('instruments only specific files and collects coverage', () => {
const {stdout} = runJest(dir, ['--coverage', '--no-cache']);
expect(stdout).toMatch('covered.js');
expect(stdout).not.toMatch('not-covered.js');
expect(stdout).not.toMatch('excluded-from-coverage.js');
// coverage result should not change
expect(stdout).toMatchSnapshot();
});
});
describe('no babel-jest', () => {
const dir = path.resolve(__dirname, '..', 'transform/no-babel-jest');
it('fails with syntax error on flow types', () => {
const {stderr} = runJest(dir, ['--no-cache']);
expect(stderr).toMatch(/FAIL.*fails-with-syntax-error/);
expect(stderr).toMatch('SyntaxError: Unexpected token :');
});
test('instrumentation with no babel-jest', () => {
const {stdout} = runJest(dir, ['--no-cache', '--coverage']);
expect(stdout).toMatch('covered.js');
expect(stdout).not.toMatch('excluded-from-coverage.js');
// coverage result should not change
expect(stdout).toMatchSnapshot();
});
});
describe('custom transformer', () => {
const dir = path.resolve(
__dirname,
'..',
'transform/custom-instrumenting-preprocessor'
);
it('proprocesses files', () => {
const {json, stderr} = runJest.json(dir, ['--no-cache']);
expect(stderr).toMatch(/FAIL/);
expect(stderr).toMatch(/instruments by setting.*global\.__INSTRUMENTED__/);
expect(json.numTotalTests).toBe(2);
expect(json.numPassedTests).toBe(1);
expect(json.numFailedTests).toBe(1);
});
it('instruments files', () => {
const {stdout, status} = runJest(dir, ['--no-cache', '--coverage']);
// coverage should be empty because there's no real instrumentation
expect(stdout).toMatchSnapshot();
expect(status).toBe(0);
});
});
describe('multiple-transformers', () => {
const dir = path.resolve(
__dirname,
'..',
'transform/multiple-transformers',
);
beforeEach(() => {
if (process.platform !== 'win32') {
run('npm install', dir);
linkJestPackage('babel-jest', dir);
}
});
it('transforms dependencies using specific transformers', () => {
const {json, stderr} = runJest.json(dir, ['--no-cache', '-u']);
expect(stderr).toMatch(/PASS/);
expect(json.numTotalTests).toBe(1);
expect(json.numPassedTests).toBe(1);
});
});