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.
Add support for globalSetup and globalTeardown in projects (jestjs#6865)
- Loading branch information
1 parent
cb5e428
commit 9781246
Showing
21 changed files
with
386 additions
and
29 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
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
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
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
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
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
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,22 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const crypto = require('crypto'); | ||
const fs = require('fs'); | ||
const mkdirp = require('mkdirp'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest-global-setup-project-1'); | ||
|
||
module.exports = function() { | ||
return new Promise((resolve, reject) => { | ||
mkdirp.sync(DIR); | ||
const fileId = crypto.randomBytes(20).toString('hex'); | ||
fs.writeFileSync(path.join(DIR, fileId), 'setup'); | ||
resolve(); | ||
}); | ||
}; |
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,20 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest-global-setup-project-1'); | ||
|
||
test('should exist setup file', () => { | ||
const files = fs.readdirSync(DIR); | ||
expect(files).toHaveLength(1); | ||
const setup = fs.readFileSync(path.join(DIR, files[0]), 'utf8'); | ||
expect(setup).toBe('setup'); | ||
}); |
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,22 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const crypto = require('crypto'); | ||
const fs = require('fs'); | ||
const mkdirp = require('mkdirp'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest-global-setup-project-2'); | ||
|
||
module.exports = function() { | ||
return new Promise((resolve, reject) => { | ||
mkdirp.sync(DIR); | ||
const fileId = crypto.randomBytes(20).toString('hex'); | ||
fs.writeFileSync(path.join(DIR, fileId), 'setup'); | ||
resolve(); | ||
}); | ||
}; |
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,20 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest-global-setup-project-2'); | ||
|
||
test('should exist setup file', () => { | ||
const files = fs.readdirSync(DIR); | ||
expect(files).toHaveLength(1); | ||
const setup = fs.readFileSync(path.join(DIR, files[0]), 'utf8'); | ||
expect(setup).toBe('setup'); | ||
}); |
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,26 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const path = require('path'); | ||
|
||
module.exports = { | ||
globalSetup: '<rootDir>/setup.js', | ||
projects: [ | ||
{ | ||
displayName: 'project-1', | ||
globalSetup: '<rootDir>/setup.js', | ||
rootDir: path.resolve(__dirname, './project-1'), | ||
testMatch: ['<rootDir>/**/*.test.js'], | ||
}, | ||
{ | ||
displayName: 'project-2', | ||
globalSetup: '<rootDir>/setup.js', | ||
rootDir: path.resolve(__dirname, './project-2'), | ||
testMatch: ['<rootDir>/**/*.test.js'], | ||
}, | ||
], | ||
}; |
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,22 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const crypto = require('crypto'); | ||
const fs = require('fs'); | ||
const mkdirp = require('mkdirp'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest-global-teardown-project-1'); | ||
|
||
module.exports = function() { | ||
return new Promise((resolve, reject) => { | ||
mkdirp.sync(DIR); | ||
const fileId = crypto.randomBytes(20).toString('hex'); | ||
fs.writeFileSync(path.join(DIR, fileId), 'teardown'); | ||
resolve(); | ||
}); | ||
}; |
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,17 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest-global-teardown-project-1'); | ||
|
||
test('should not exist teardown file', () => { | ||
expect(fs.existsSync(DIR)).toBe(false); | ||
}); |
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,22 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const crypto = require('crypto'); | ||
const fs = require('fs'); | ||
const mkdirp = require('mkdirp'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest-global-teardown-project-2'); | ||
|
||
module.exports = function() { | ||
return new Promise((resolve, reject) => { | ||
mkdirp.sync(DIR); | ||
const fileId = crypto.randomBytes(20).toString('hex'); | ||
fs.writeFileSync(path.join(DIR, fileId), 'teardown'); | ||
resolve(); | ||
}); | ||
}; |
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,17 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
const DIR = path.join(os.tmpdir(), 'jest-global-teardown-project-2'); | ||
|
||
test('teardown file should not exist', () => { | ||
expect(fs.existsSync(DIR)).toBe(false); | ||
}); |
Oops, something went wrong.