-
Notifications
You must be signed in to change notification settings - Fork 8
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 #2015 from cardstack/shard-server-tests
shard realm server tests
- Loading branch information
Showing
15 changed files
with
7,748 additions
and
7,440 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { readFileSync, readdirSync } from 'fs-extra'; | ||
import yaml from 'js-yaml'; | ||
import { join, basename } from 'path'; | ||
|
||
const YAML_FILE = join( | ||
__dirname, | ||
'..', | ||
'..', | ||
'..', | ||
'.github', | ||
'workflows', | ||
'ci.yaml', | ||
); | ||
const TEST_DIR = join(__dirname, '..', 'tests'); | ||
|
||
function getCiTestModules(yamlFilePath: string) { | ||
try { | ||
const yamlContent = readFileSync(yamlFilePath, 'utf8'); | ||
const yamlData = yaml.load(yamlContent) as Record<string, any>; | ||
|
||
const shardIndexes: string[] = | ||
yamlData?.jobs?.['realm-server-test']?.strategy?.matrix?.testModule; | ||
|
||
if (!Array.isArray(shardIndexes)) { | ||
throw new Error( | ||
`Invalid 'jobs.realm-server-test.strategy.matrix.testModule' format in the YAML file.`, | ||
); | ||
} | ||
|
||
return shardIndexes; | ||
} catch (error: any) { | ||
console.error(`Error reading shardIndex from YAML file: ${error.message}`); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
function getFilesystemTestModules(testDir: string) { | ||
try { | ||
const files = readdirSync(testDir); | ||
return files | ||
.filter((file) => file.endsWith('-test.ts')) | ||
.map((file) => basename(file)); | ||
} catch (error: any) { | ||
console.error( | ||
`Error reading test files from dir ${testDir}: ${error.message}`, | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
function validateTestFiles(yamlFilePath: string, testDir: string) { | ||
const ciTestModules = getCiTestModules(yamlFilePath); | ||
const filesystemTestModules = getFilesystemTestModules(testDir); | ||
|
||
let errorFound = false; | ||
|
||
for (let filename of filesystemTestModules) { | ||
if (!ciTestModules.includes(filename)) { | ||
console.error( | ||
`Error: Test file '${filename}' exists in the filesystem but not in the ${yamlFilePath} file.`, | ||
); | ||
errorFound = true; | ||
} | ||
} | ||
for (let filename of ciTestModules) { | ||
if (!filesystemTestModules.includes(filename)) { | ||
console.error( | ||
`Error: Test file '${filename}' exists in the YAML file but not in the filesystem.`, | ||
); | ||
errorFound = true; | ||
} | ||
} | ||
|
||
if (errorFound) { | ||
process.exit(1); | ||
} else { | ||
console.log( | ||
`All test files are accounted for in the ${yamlFilePath} file for the realm-server matrix strategy.`, | ||
); | ||
} | ||
} | ||
|
||
validateTestFiles(YAML_FILE, TEST_DIR); |
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
Oops, something went wrong.