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

Add fallback logic #539

Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
17 changes: 15 additions & 2 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -1022,7 +1036,6 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => {
}
}

let ignoreFiles = args.exclude || bsConfig.run_settings.exclude
let fileMatchedWithConfigSpecPattern = []
globCypressConfigSpecPatterns.forEach(specPattern => {
fileMatchedWithConfigSpecPattern.push(
Expand Down
39 changes: 32 additions & 7 deletions test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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([
Expand All @@ -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', () => {
Expand Down