diff --git a/bin/commands/runs.js b/bin/commands/runs.js index d1ad1bb8..55c4125d 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -128,8 +128,11 @@ module.exports = function run(args, rawArgs) { logger.debug("Completed configs validation"); markBlockStart('preArchiveSteps'); logger.debug("Started pre-archive steps"); + //get the number of spec files + markBlockStart('getNumberOfSpecFiles'); let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressConfigFile); + markBlockEnd('getNumberOfSpecFiles'); bsConfig['run_settings']['video_config'] = utils.getVideoConfig(cypressConfigFile); diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 80a19be6..5b593d29 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -990,6 +990,7 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => { let testFolderPath let globCypressConfigSpecPatterns = [] let globSearchPattern = this.sanitizeSpecsPattern(bsConfig.run_settings.specs); + let ignoreFiles = args.exclude || bsConfig.run_settings.exclude if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) { defaultSpecFolder = Constants.DEFAULT_CYPRESS_10_SPEC_PATH @@ -1002,8 +1003,21 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => { globCypressConfigSpecPatterns = [`${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`] } } else { - // if not able read cypress config, use bstack specs arg(existing logic, which is not correct) + // if not able read cypress config + // use bstack specs arg(existing logic, which is not correct) if bstack specs arg not provided check for cypress/e2e folder globCypressConfigSpecPatterns = globSearchPattern ? [globSearchPattern] : [`${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`] + const filesMatched = []; + globCypressConfigSpecPatterns.forEach(specPattern => { + filesMatched.push( + ...glob.sync(specPattern, { + cwd: bsConfig.run_settings.cypressProjectDir, matchBase: true, ignore: ignoreFiles + }) + ); + }); + if (!filesMatched.length) { + // if no files found under cypress/e2e check for cypress/integration + globCypressConfigSpecPatterns = [`${Constants.DEFAULT_CYPRESS_SPEC_PATH}/**/*.+(${Constants.specFileTypes.join("|")})`] + } } } else { defaultSpecFolder = Constants.DEFAULT_CYPRESS_SPEC_PATH @@ -1022,7 +1036,6 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => { } } - let ignoreFiles = args.exclude || bsConfig.run_settings.exclude let fileMatchedWithConfigSpecPattern = [] globCypressConfigSpecPatterns.forEach(specPattern => { fileMatchedWithConfigSpecPattern.push( diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index ad8d175c..edfd9c30 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -2502,12 +2502,6 @@ describe('utils', () => { let globStub = sinon.stub(glob, 'sync') globStub.withArgs('cypress/e2e/foo*.js') .returns(['cypress/e2e/foo_1.js']); - // globStub.withArgs(`cypress/e2e/**/*.+(${constant.specFileTypes.join('|')})`) - // .returns([ - // 'cypress/e2e/foo_1.js', - // 'cypress/e2e/foo_2.js', - // 'cypress/e2e/bar_1.js' - // ]); let bsConfig = { run_settings: { cypressTestSuiteType: 'CYPRESS_V10_AND_ABOVE_TYPE', @@ -2528,7 +2522,7 @@ describe('utils', () => { glob.sync.restore(); }); - it('should return under default folder if cypress v >= 10 and error while reading config file', () => { + it('should return files under default e2e folder if cypress v >= 10 and error while reading config file', () => { let globStub = sinon.stub(glob, 'sync') globStub.withArgs(`cypress/e2e/**/*.+(${constant.specFileTypes.join('|')})`) .returns([ @@ -2554,6 +2548,37 @@ describe('utils', () => { }) glob.sync.restore(); }); + + 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', () => { + let globStub = sinon.stub(glob, 'sync') + globStub.withArgs(`cypress/e2e/**/*.+(${constant.specFileTypes.join('|')})`) + .returns([]); + globStub.withArgs(`cypress/integration/**/*.+(${constant.specFileTypes.join('|')})`) + .returns([ + 'cypress/integration/foo_1.js', + 'cypress/integration/foo_2.js', + 'cypress/integration/bar_1.js' + ]); + let bsConfig = { + run_settings: { + cypressTestSuiteType: 'CYPRESS_V10_AND_ABOVE_TYPE', + cypressProjectDir: 'cypressProjectDir', + exclude: 'exclude', + }, + }; + + const result = utils.getNumberOfSpecFiles(bsConfig, {}, null); + expect(result.length).to.eql(3); + expect(result[0].endsWith('cypress/integration/foo_1.js')).to.eql(true); + expect(result[1].endsWith('cypress/integration/foo_2.js')).to.eql(true); + expect(result[2].endsWith('cypress/integration/bar_1.js')).to.eql(true); + sinon.assert.calledWithExactly(globStub, `cypress/e2e/**/*.+(${constant.specFileTypes.join('|')})`, { + cwd: 'cypressProjectDir', + matchBase: true, + ignore: 'exclude', + }) + glob.sync.restore(); + }); }); describe('warnSpecLimit', () => {