|
| 1 | +var _ = require('lodash'); |
| 2 | +var log = require('winston'); |
| 3 | +var path = require('canonical-path'); |
| 4 | +var trimIndentation = require('dgeni/lib/utils/trim-indentation'); |
| 5 | +var code = require('dgeni/lib/utils/code'); |
| 6 | +var protractorFolder; |
| 7 | + |
| 8 | +module.exports = { |
| 9 | + name: 'protractor-generate', |
| 10 | + description: 'Generate a protractor test file from the e2e tests in the examples', |
| 11 | + runAfter: ['adding-extra-docs'], |
| 12 | + runBefore: ['extra-docs-added'], |
| 13 | + init: function(config, injectables) { |
| 14 | + protractorFolder = config.get('rendering.protractor.outputFolder', 'ptore2e'); |
| 15 | + }, |
| 16 | + process: function(docs, examples) { |
| 17 | + _.forEach(examples, function(example) { |
| 18 | + |
| 19 | + _.forEach(example.files, function(file) { |
| 20 | + |
| 21 | + // Check if it's a Protractor test. |
| 22 | + if (!(file.type == 'protractor')) { |
| 23 | + return; |
| 24 | + } |
| 25 | + |
| 26 | + // Create a new file for the test. |
| 27 | + // TODO - at the moment, only jqLite is being used. Will need to generate |
| 28 | + // another doc for jQuery if we want to test against that. |
| 29 | + var protractorDoc = { |
| 30 | + docType: 'e2e-test', |
| 31 | + id: 'protractorTest' + '-' + example.id, |
| 32 | + template: 'protractorTests.template.js', |
| 33 | + outputPath: path.join(protractorFolder, example.id, 'jqlite' + '_test.js'), |
| 34 | + innerTest: file.fileContents, |
| 35 | + pathPrefix: '.', // Hold for if we test with full jQuery |
| 36 | + exampleId: example.id, |
| 37 | + description: example.doc.id, |
| 38 | + examplePath: example.outputFolder + '/index.html' |
| 39 | + }; |
| 40 | + |
| 41 | + docs.push(protractorDoc); |
| 42 | + }); |
| 43 | + }); |
| 44 | + } |
| 45 | +}; |
0 commit comments