Skip to content

Commit eec0ab1

Browse files
Merge pull request #539 from browserstack/AFD-1922-default-folder-v10-onwards
Add fallback logic
2 parents 649bf75 + fd65a7a commit eec0ab1

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

bin/commands/runs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ module.exports = function run(args, rawArgs) {
128128
logger.debug("Completed configs validation");
129129
markBlockStart('preArchiveSteps');
130130
logger.debug("Started pre-archive steps");
131+
131132
//get the number of spec files
133+
markBlockStart('getNumberOfSpecFiles');
132134
let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressConfigFile);
135+
markBlockEnd('getNumberOfSpecFiles');
133136

134137
bsConfig['run_settings']['video_config'] = utils.getVideoConfig(cypressConfigFile);
135138

bin/helpers/utils.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => {
990990
let testFolderPath
991991
let globCypressConfigSpecPatterns = []
992992
let globSearchPattern = this.sanitizeSpecsPattern(bsConfig.run_settings.specs);
993+
let ignoreFiles = args.exclude || bsConfig.run_settings.exclude
993994

994995
if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
995996
defaultSpecFolder = Constants.DEFAULT_CYPRESS_10_SPEC_PATH
@@ -1002,8 +1003,21 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => {
10021003
globCypressConfigSpecPatterns = [`${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`]
10031004
}
10041005
} else {
1005-
// if not able read cypress config, use bstack specs arg(existing logic, which is not correct)
1006+
// if not able read cypress config
1007+
// use bstack specs arg(existing logic, which is not correct) if bstack specs arg not provided check for cypress/e2e folder
10061008
globCypressConfigSpecPatterns = globSearchPattern ? [globSearchPattern] : [`${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`]
1009+
const filesMatched = [];
1010+
globCypressConfigSpecPatterns.forEach(specPattern => {
1011+
filesMatched.push(
1012+
...glob.sync(specPattern, {
1013+
cwd: bsConfig.run_settings.cypressProjectDir, matchBase: true, ignore: ignoreFiles
1014+
})
1015+
);
1016+
});
1017+
if (!filesMatched.length) {
1018+
// if no files found under cypress/e2e check for cypress/integration
1019+
globCypressConfigSpecPatterns = [`${Constants.DEFAULT_CYPRESS_SPEC_PATH}/**/*.+(${Constants.specFileTypes.join("|")})`]
1020+
}
10071021
}
10081022
} else {
10091023
defaultSpecFolder = Constants.DEFAULT_CYPRESS_SPEC_PATH
@@ -1022,7 +1036,6 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => {
10221036
}
10231037
}
10241038

1025-
let ignoreFiles = args.exclude || bsConfig.run_settings.exclude
10261039
let fileMatchedWithConfigSpecPattern = []
10271040
globCypressConfigSpecPatterns.forEach(specPattern => {
10281041
fileMatchedWithConfigSpecPattern.push(

test/unit/bin/helpers/utils.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,12 +2502,6 @@ describe('utils', () => {
25022502
let globStub = sinon.stub(glob, 'sync')
25032503
globStub.withArgs('cypress/e2e/foo*.js')
25042504
.returns(['cypress/e2e/foo_1.js']);
2505-
// globStub.withArgs(`cypress/e2e/**/*.+(${constant.specFileTypes.join('|')})`)
2506-
// .returns([
2507-
// 'cypress/e2e/foo_1.js',
2508-
// 'cypress/e2e/foo_2.js',
2509-
// 'cypress/e2e/bar_1.js'
2510-
// ]);
25112505
let bsConfig = {
25122506
run_settings: {
25132507
cypressTestSuiteType: 'CYPRESS_V10_AND_ABOVE_TYPE',
@@ -2528,7 +2522,7 @@ describe('utils', () => {
25282522
glob.sync.restore();
25292523
});
25302524

2531-
it('should return under default folder if cypress v >= 10 and error while reading config file', () => {
2525+
it('should return files under default e2e folder if cypress v >= 10 and error while reading config file', () => {
25322526
let globStub = sinon.stub(glob, 'sync')
25332527
globStub.withArgs(`cypress/e2e/**/*.+(${constant.specFileTypes.join('|')})`)
25342528
.returns([
@@ -2554,6 +2548,37 @@ describe('utils', () => {
25542548
})
25552549
glob.sync.restore();
25562550
});
2551+
2552+
it('should return files under integration folder if cypress v >= 10, no spec arg in bstack.json and error while reading config file and no files under cypress/e2e', () => {
2553+
let globStub = sinon.stub(glob, 'sync')
2554+
globStub.withArgs(`cypress/e2e/**/*.+(${constant.specFileTypes.join('|')})`)
2555+
.returns([]);
2556+
globStub.withArgs(`cypress/integration/**/*.+(${constant.specFileTypes.join('|')})`)
2557+
.returns([
2558+
'cypress/integration/foo_1.js',
2559+
'cypress/integration/foo_2.js',
2560+
'cypress/integration/bar_1.js'
2561+
]);
2562+
let bsConfig = {
2563+
run_settings: {
2564+
cypressTestSuiteType: 'CYPRESS_V10_AND_ABOVE_TYPE',
2565+
cypressProjectDir: 'cypressProjectDir',
2566+
exclude: 'exclude',
2567+
},
2568+
};
2569+
2570+
const result = utils.getNumberOfSpecFiles(bsConfig, {}, null);
2571+
expect(result.length).to.eql(3);
2572+
expect(result[0].endsWith('cypress/integration/foo_1.js')).to.eql(true);
2573+
expect(result[1].endsWith('cypress/integration/foo_2.js')).to.eql(true);
2574+
expect(result[2].endsWith('cypress/integration/bar_1.js')).to.eql(true);
2575+
sinon.assert.calledWithExactly(globStub, `cypress/e2e/**/*.+(${constant.specFileTypes.join('|')})`, {
2576+
cwd: 'cypressProjectDir',
2577+
matchBase: true,
2578+
ignore: 'exclude',
2579+
})
2580+
glob.sync.restore();
2581+
});
25572582
});
25582583

25592584
describe('warnSpecLimit', () => {

0 commit comments

Comments
 (0)