| 
 | 1 | +import JestBuilder from './jest.builder';  | 
 | 2 | +import { normalize } from '@angular-devkit/core';  | 
 | 3 | +import * as jestCLI from 'jest-cli';  | 
 | 4 | +import * as path from 'path';  | 
 | 5 | + | 
 | 6 | +describe('Jest Builder', () => {  | 
 | 7 | + let builder: JestBuilder;  | 
 | 8 | + | 
 | 9 | + beforeEach(() => {  | 
 | 10 | + builder = new JestBuilder();  | 
 | 11 | + });  | 
 | 12 | + | 
 | 13 | + it('should send appropriate options to jestCLI', () => {  | 
 | 14 | + const runCLI = spyOn(jestCLI, 'runCLI').and.returnValue(  | 
 | 15 | + Promise.resolve({  | 
 | 16 | + results: {  | 
 | 17 | + success: true  | 
 | 18 | + }  | 
 | 19 | + })  | 
 | 20 | + );  | 
 | 21 | + const root = normalize('/root');  | 
 | 22 | + builder  | 
 | 23 | + .run({  | 
 | 24 | + root,  | 
 | 25 | + builder: '',  | 
 | 26 | + projectType: 'application',  | 
 | 27 | + options: {  | 
 | 28 | + jestConfig: './jest.config.js',  | 
 | 29 | + tsConfig: './tsconfig.test.json',  | 
 | 30 | + watch: false  | 
 | 31 | + }  | 
 | 32 | + })  | 
 | 33 | + .toPromise();  | 
 | 34 | + expect(runCLI).toHaveBeenCalledWith(  | 
 | 35 | + {  | 
 | 36 | + globals: JSON.stringify({  | 
 | 37 | + 'ts-jest': {  | 
 | 38 | + tsConfigFile: path.relative(root, './tsconfig.test.json')  | 
 | 39 | + },  | 
 | 40 | + __TRANSFORM_HTML__: true  | 
 | 41 | + }),  | 
 | 42 | + watch: false  | 
 | 43 | + },  | 
 | 44 | + ['./jest.config.js']  | 
 | 45 | + );  | 
 | 46 | + });  | 
 | 47 | + | 
 | 48 | + it('should send the setupFile to jestCLI', () => {  | 
 | 49 | + const runCLI = spyOn(jestCLI, 'runCLI').and.returnValue(  | 
 | 50 | + Promise.resolve({  | 
 | 51 | + results: {  | 
 | 52 | + success: true  | 
 | 53 | + }  | 
 | 54 | + })  | 
 | 55 | + );  | 
 | 56 | + const root = normalize('/root');  | 
 | 57 | + builder  | 
 | 58 | + .run({  | 
 | 59 | + root,  | 
 | 60 | + builder: '',  | 
 | 61 | + projectType: 'application',  | 
 | 62 | + options: {  | 
 | 63 | + jestConfig: './jest.config.js',  | 
 | 64 | + tsConfig: './tsconfig.test.json',  | 
 | 65 | + setupFile: './test.ts',  | 
 | 66 | + watch: false  | 
 | 67 | + }  | 
 | 68 | + })  | 
 | 69 | + .toPromise();  | 
 | 70 | + expect(runCLI).toHaveBeenCalledWith(  | 
 | 71 | + {  | 
 | 72 | + globals: JSON.stringify({  | 
 | 73 | + 'ts-jest': {  | 
 | 74 | + tsConfigFile: path.relative(root, './tsconfig.test.json')  | 
 | 75 | + },  | 
 | 76 | + __TRANSFORM_HTML__: true  | 
 | 77 | + }),  | 
 | 78 | + setupTestFrameworkScriptFile: path.join(  | 
 | 79 | + '<rootDir>',  | 
 | 80 | + path.relative(root, './test.ts')  | 
 | 81 | + ),  | 
 | 82 | + watch: false  | 
 | 83 | + },  | 
 | 84 | + ['./jest.config.js']  | 
 | 85 | + );  | 
 | 86 | + });  | 
 | 87 | + | 
 | 88 | + it('should return the proper result', async done => {  | 
 | 89 | + spyOn(jestCLI, 'runCLI').and.returnValue(  | 
 | 90 | + Promise.resolve({  | 
 | 91 | + results: {  | 
 | 92 | + success: true  | 
 | 93 | + }  | 
 | 94 | + })  | 
 | 95 | + );  | 
 | 96 | + const root = normalize('/root');  | 
 | 97 | + const result = await builder  | 
 | 98 | + .run({  | 
 | 99 | + root,  | 
 | 100 | + builder: '',  | 
 | 101 | + projectType: 'application',  | 
 | 102 | + options: {  | 
 | 103 | + jestConfig: './jest.config.js',  | 
 | 104 | + tsConfig: './tsconfig.test.json',  | 
 | 105 | + watch: false  | 
 | 106 | + }  | 
 | 107 | + })  | 
 | 108 | + .toPromise();  | 
 | 109 | + expect(result).toEqual({  | 
 | 110 | + success: true  | 
 | 111 | + });  | 
 | 112 | + done();  | 
 | 113 | + });  | 
 | 114 | +});  | 
0 commit comments