Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runNodeScript.js, add includeFiles and create a test report #927

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions scripts/sw-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ By default we'll use the `SW_TEST_CONFIG` environment variable to load the confi
| `env` | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| `ignoreTests` | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| `ignoreFiles` | :x: | :x: | :white_check_mark: |
| `includeFiles` | :x: | :x: | :white_check_mark: |

### `env` (`Object`): Environment Variables
You can define the environment variables to be used in your tests in a single spot using JS Object notation.
Expand Down Expand Up @@ -62,3 +63,13 @@ Example:
```
SW_TEST_CONFIG='{ "ignoreFiles": ["voice.test.ts"] }'
```

### `includeFiles` (`string[]`): Include Files by name.
Any files that match the given name will be used.

Example:
```
SW_TEST_CONFIG='{ "includeFiles": ["voiceCollect/withAllListeners.test.ts", "voicePlayback/withPlaybackListeners.test.ts"] }'
```

This is optional.
23 changes: 19 additions & 4 deletions scripts/sw-test/runNodeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ALLOWED_SCRIPT_EXTENSIONS = ['js', 'ts']

const getScriptOptions = (pathname, config) => {
const ignoreFiles = config.ignoreFiles || []
const includeFiles = config.includeFiles || undefined
const ignoreDirectories = config.ignoreDirectories
? [...config.ignoreDirectories, 'playwright']
: ['playwright']
Expand All @@ -35,7 +36,8 @@ const getScriptOptions = (pathname, config) => {

if (
fs.lstatSync(itemPath).isFile() &&
normalizedPath.includes('.test.') &&
(((includeFiles === undefined) && normalizedPath.includes('.test.')) ||
((includeFiles !== undefined) && includeFiles.includes(normalizedPath))) &&
giavac marked this conversation as resolved.
Show resolved Hide resolved
!ignoreFiles.includes(normalizedPath)
) {
acc.push({
Expand Down Expand Up @@ -78,10 +80,11 @@ const getRunParams = (script) => {

async function runNodeScript(config) {
const tests = getScriptOptions(path.join(process.cwd(), './src'), config)
let testResults = []
let runFailed = false
try {
for await (const test of tests) {
await new Promise((resolve, reject) => {
console.log('Running Test', test.name)
const child = spawn(...getRunParams(test))

child.stdout.on('data', (data) => {
Expand All @@ -94,16 +97,28 @@ async function runNodeScript(config) {

child.on('close', (exitCode) => {
if (exitCode !== 0) {
reject(exitCode)
console.log("Adding to FAILED tests: ", test.name)
testResults.push({ "test": test.name, "result": "FAIL", "exitCode": exitCode, "time": Date.now()})
runFailed = true
resolve()
} else {
console.log("Adding to passed tests: ", test.name)
testResults.push({ "test": test.name, "result": "OK", "time": Date.now()})
resolve()
}
resolve()
})
})
}
} catch (error) {
console.error('Process Exit with errorCode', error)
process.exit(error ?? 1)
}
console.log("--------- test results: ", testResults)
giavac marked this conversation as resolved.
Show resolved Hide resolved
console.log("-------------------------------------------")

if (runFailed === true) {
process.exit(1)
}
}

exports.runNodeScript = runNodeScript
Loading