File tree Expand file tree Collapse file tree
packages/jest-runtime/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515- ` [jest-resolve-dependencies] ` Resolve mocks as dependencies ([ #10713 ] ( https://github.com/facebook/jest/pull/10713 ) )
1616- ` [jest-runtime] ` Handle file URLs in dynamic imports ([ #10744 ] ( https://github.com/facebook/jest/pull/10744 ) )
1717- ` [jest-runtime, babel-jest] ` Pass more ESM options to ` @jest/transform ` ([ #10752 ] ( https://github.com/facebook/jest/pull/10752 ) )
18+ - ` [jest-runtime] ` Properly inject ` extraGlobals ` into the runtime ([ #10758 ] ( https://github.com/facebook/jest/pull/10758 ) )
1819- ` [jest-transform] ` Link to ESM docs on syntax errors ([ #10748 ] ( https://github.com/facebook/jest/pull/10748 ) )
1920
2021### Chore & Maintenance
Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+ *
4+ * This source code is licensed under the MIT license found in the
5+ * LICENSE file in the root directory of this source tree.
6+ */
7+
8+ import { tmpdir } from 'os' ;
9+ import * as path from 'path' ;
10+ import { cleanup , createEmptyPackage , writeFiles } from '../Utils' ;
11+ import { json as runJest } from '../runJest' ;
12+
13+ const DIR = path . resolve ( tmpdir ( ) , 'extra-globals' ) ;
14+
15+ beforeEach ( ( ) => {
16+ cleanup ( DIR ) ;
17+ createEmptyPackage ( DIR , { jest : { extraGlobals : [ 'Math' ] } } ) ;
18+ } ) ;
19+
20+ afterAll ( ( ) => cleanup ( DIR ) ) ;
21+
22+ test ( 'works with injected globals' , ( ) => {
23+ writeFiles ( DIR , {
24+ 'test.js' : `
25+ test('Math works when injected', () => {
26+ expect(Math.floor(1.5)).toBe(1);
27+ });
28+ ` ,
29+ } ) ;
30+
31+ const { exitCode} = runJest ( DIR ) ;
32+
33+ expect ( exitCode ) . toBe ( 0 ) ;
34+ } ) ;
Original file line number Diff line number Diff line change @@ -1095,9 +1095,9 @@ class Runtime {
10951095
10961096 this . jestObjectCaches . set ( filename , jestObject ) ;
10971097
1098- const lastArgs : [ Jest | undefined , ...Array < any > ] = [
1098+ const lastArgs : [ Jest | undefined , ...Array < Global . Global > ] = [
10991099 this . _config . injectGlobals ? jestObject : undefined , // jest object
1100- this . _config . extraGlobals . map < unknown > ( globalVariable => {
1100+ ... this . _config . extraGlobals . map < Global . Global > ( globalVariable => {
11011101 if ( this . _environment . global [ globalVariable ] ) {
11021102 return this . _environment . global [ globalVariable ] ;
11031103 }
@@ -1126,6 +1126,7 @@ class Runtime {
11261126 module . path , // __dirname
11271127 module . filename , // __filename
11281128 this . _environment . global , // global object
1129+ // @ts -expect-error
11291130 ...lastArgs . filter ( notEmpty ) ,
11301131 ) ;
11311132 } catch ( error ) {
You can’t perform that action at this time.
0 commit comments