-
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.
Merge pull request #29 from MSA-Safety/feat/demo
test: Add demo project for testing and showcasing the package
- Loading branch information
Showing
13 changed files
with
7,575 additions
and
8,430 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v18 |
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,30 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
|
||
/** | ||
* Main function. Writes file if it does not exist yet and throws. | ||
* Succeeds and deletes file if file exists. | ||
* | ||
* Ergo: first call fails - second call succeeds. | ||
* | ||
* Please note: this is not intended to represent a good example where | ||
* this package might be helpful. More appropriate usages are network | ||
* flakiness in integration/e2e tests. | ||
* | ||
* @throws {Error} If file did not exist. | ||
*/ | ||
function demo() { | ||
const path = './demo-unit-text.txt'; | ||
|
||
if (!fs.existsSync(path)) { | ||
// File does not exist yet, create file and throw error | ||
fs.writeFileSync(path, '0'); | ||
throw new Error('Random Flaky Error'); | ||
} | ||
|
||
// File exists, delete it and be happy | ||
fs.rmSync(path); | ||
} | ||
|
||
module.exports = { demo }; |
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,15 @@ | ||
'use strict'; | ||
|
||
const { demo } = require('./demo'); | ||
|
||
describe('demo', () => { | ||
it('should fail on first test run and succeed on subsequent run', () => { | ||
let caughtError; | ||
try { | ||
demo(); | ||
} catch (error) { | ||
caughtError = error; | ||
} | ||
expect(caughtError).toBeUndefined(); | ||
}); | ||
}); |
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,32 @@ | ||
/** | ||
* NodeJS unit test Jest config. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
coverageDirectory: 'build/coverage/unit', | ||
coveragePathIgnorePatterns: ['node_modules'], | ||
coverageThreshold: { | ||
global: { | ||
branches: 95, | ||
functions: 95, | ||
lines: 95, | ||
statements: 95, | ||
}, | ||
}, | ||
moduleNameMapper: {}, | ||
reporters: [ | ||
'default', | ||
[ | ||
'<rootDir>/..', | ||
{ | ||
configFile: 'jest.unit.flakyRetry.json', | ||
junitOutputDirectory: 'build/results/unit', | ||
}, | ||
], | ||
], | ||
roots: ['<rootDir>'], | ||
testEnvironment: 'node', | ||
testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)+(unit.test).js?(x)'], | ||
}; |
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,7 @@ | ||
[ | ||
{ | ||
"failureMessages": [ | ||
"Random Flaky Error" | ||
] | ||
} | ||
] |
Oops, something went wrong.