Created
February 7, 2021 18:22
-
-
Save dualyticalchemy/28f5faae6ae1e68035353fe6facd10b1 to your computer and use it in GitHub Desktop.
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
import { Given, When, Then } from '../../tests/bdd'; | |
import { compose } from '../../tests/bdd/utils/compose.js'; | |
const { load } = require('../../tests/bdd/utils/load.js'); | |
const config = async () => { | |
const platformConf = await load(__dirname, 'platform.conf.json'); | |
cy.log('reading file'); | |
cy.log(platformConf); | |
return platformConf; | |
}; | |
const { has } = require('../../tests/e2e/utils/has.js')(config(), 'homeUnitTabletConfig'); | |
const files = [ | |
'tests/bdd/features/given_test.feature', | |
'tests/bdd/features/index.feature', | |
'tests/bdd/features/ZOLL-UI__homeUnit--hamburgerMenu.feature', | |
]; | |
const constructTest = compose(function (res) { | |
cy.log('last pass:', JSON.stringify( res.body )); | |
return res; | |
}, function (res) { | |
cy.log('second pass:', res.body); | |
return res; | |
}, async function (str) { | |
cy.log('first pass:'); | |
const given = await Given({text: str}); | |
const hasIPad = has('iPad'); | |
cy.log(hasIPad); | |
const when = await When({text: str, context: hasIPad}); | |
const conditions = { | |
given: given, | |
when: when | |
}; | |
return Then(conditions)(str); | |
}); | |
/** | |
* loadTestSuite | |
* @description | |
* A simple test runner that composes tests out of feature files and bespoke | |
* Gherkin-ready methods for Given, When, Then. | |
* @param array paths Pass in an array of file paths to be read off according | |
* to Gherkin-style syntax. | |
* @return undefined | |
*/ | |
const loadTestSuite = (paths) => { | |
const baseUrl = Cypress.env('baseUrl') || 'http://localhost:8000'; | |
(paths).forEach((featurePath) => { | |
const icon = ['🧭']; | |
const description = [icon[0], '[', '@' + featurePath, '] ...'].join(' '); | |
describe(description, function () { | |
it('pass', function () { | |
if (!featurePath) { | |
cy.log('@invalid: ' + featurePath); | |
return; | |
} | |
cy.visit([baseUrl].join('')) | |
.then((contentWindow) => { | |
cy.log('🔮 found AngularJS ...'); | |
expect(contentWindow.angular).to.exist; | |
expect('get' in cy.window().its('localStorage')).to.be.true; | |
cy.log('🔬 validating feature file ...'); | |
cy.readFile(featurePath) | |
.then(async (str) => { | |
cy.log('@valid: ' + featurePath); | |
expect(str).to.exist; | |
const testSuite = await constructTest(str); | |
expect(testSuite.res).to.be.a('string'); | |
}); | |
}); | |
}); | |
}); | |
}); | |
} | |
loadTestSuite(files); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment