Skip to content

Commit ce8a008

Browse files
authored
fix: update test_conditions to beter report (#184)
Offer a way to override issues Integrate into CI
1 parent 796af98 commit ce8a008

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

buildspec.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ phases:
1111
build:
1212
commands:
1313
- npm test
14+
- npm run test_conditions
1415
- npm run integration

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"integration-node-decrypt": "npm run build; lerna run integration_node --stream --no-prefix -- -- decrypt -v $npm_package_config_localTestVectors",
2626
"integration-node-encrypt": "npm run build; lerna run integration_node --stream --no-prefix -- -- encrypt -m $npm_package_config_encryptManifestList -k $npm_package_config_encryptKeyManifest -o $npm_package_config_decryptOracle",
2727
"integration-node": "run-s integration-node-*",
28-
"integration": "run-s integration-*"
28+
"integration": "run-s integration-*",
29+
"test_conditions": "./util/bootstrap_tsconfig 23"
2930
},
3031
"config": {
3132
"localTestVectors": "../../aws-encryption-sdk-test-vectors/vectors/awses-decrypt/python-1.3.8.zip",

util/test_conditions

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515
*/
1616

1717
/* This file is to help line up the formal conditions listed in source with tests.
18-
* I look for `sourceGrep` and `testGrep` make make sure that the conditions found,
19-
* are in both sets.
20-
*/
18+
* I look for `sourceGrep` and `testGrep` make make sure that the conditions found,
19+
* are in both sets.
20+
*/
2121

2222
const { exec } = require('child_process')
2323
const { promisify } = require('util')
2424
const execAsync = promisify(exec)
2525

26-
const sourceGrep = 'grep -E \'Precondition|Postcondition\' modules/**/src/*.ts'
27-
const testGrep = 'grep -E \'Precondition|Postcondition\' modules/**/test/*.ts'
26+
const ignoreIssueCount = parseInt(process.argv[2] || 0, 10)
27+
28+
const sourceGrep = 'grep -E \'Precondition:|Postcondition(:|\\):)\' modules/**/src/*.ts'
29+
const testGrep = 'grep -E \'Precondition:|Postcondition(:|\\):)\' modules/**/test/*.ts'
2830

2931
Promise.all([
3032
execAsync(sourceGrep).then(clean),
@@ -36,12 +38,15 @@ Promise.all([
3638
const testSet = new Set(flatMapForTests(tests))
3739

3840
if (source.length > sourceSet.size) {
39-
console.log('Duplicate source conditions', getDuplicates(source))
40-
issues += 1
41+
const duplicateSources = getDuplicates(source)
42+
console.log('Duplicate source conditions', duplicateSources)
43+
issues += duplicateSources.length
4144
}
42-
if (tests.length > testSet.size) {
43-
console.log('Duplicate test conditions', getDuplicates(tests))
44-
issues += 1
45+
// A single test _may_ be multiple conditions.
46+
const duplicateTests = getDuplicates(tests)
47+
if (duplicateTests.length) {
48+
console.log('Duplicate test conditions', duplicateTests)
49+
issues += duplicateTests.length
4550
}
4651

4752
for (const sourceCondition of sourceSet) {
@@ -58,12 +63,16 @@ Promise.all([
5863
}
5964
}
6065

61-
process.exit(issues)
66+
if (issues) {
67+
console.error(`Issue count found: ${issues}`)
68+
}
69+
70+
process.exit(Math.max(0, issues - ignoreIssueCount))
6271
})
6372

64-
const remove = /(\*\/)|(\/\*)|(it\(')|(', \(\) => \{)|(', async \(\) => \{)/g
73+
const remove = /(\*\/)|(\/\*)|(it\([`'])|([`'], \(\) => \{)|([`'], async \(\) => \{)/g
6574

66-
function clean ({ stdout, stderr }) {
75+
function clean ({ stdout }) {
6776
return stdout.split('\n')
6877
.map(l => l.replace(remove, ''))
6978
// Do not try and clean up ' and things like that...

0 commit comments

Comments
 (0)