Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit d5d9393

Browse files
authored
chore(website): fix website tests (#4080)
Also added npm command `compile_to_es5` to make running the website tests easier
1 parent a5c7786 commit d5d9393

File tree

9 files changed

+81
-29
lines changed

9 files changed

+81
-29
lines changed

gulpfile.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ gulp.task('tsc:spec', function(done) {
9898
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc', '-p', 'ts_spec_config.json']);
9999
});
100100

101+
gulp.task('tsc:es5', function(done) {
102+
runSpawn(done, './scripts/compile_to_es5.sh');
103+
});
104+
105+
gulp.task('compile_to_es5', function(done) {
106+
runSequence('checkVersion', 'tsc:es5', 'built:copy', done);
107+
});
108+
101109
gulp.task('prepublish', function(done) {
102110
runSequence('checkVersion', 'jshint', 'tsc', 'built:copy', done);
103111
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
"pretest": "gulp pretest",
7575
"start": "cd testapp && npm start",
7676
"test": "node scripts/test.js",
77-
"website": "cd website && npm start"
77+
"website": "cd website && npm start",
78+
"compile_to_es5": "gulp compile_to_es5"
7879
},
7980
"license": "MIT",
8081
"engines": {

scripts/compile_to_es5.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
cd "$( dirname "${BASH_SOURCE[0]}" )/.."
3+
4+
# Check number of parameters
5+
if [ "$#" -gt 0 ]; then
6+
echo "Usage: ./scripts/compile_to_es5.sh"
7+
exit 1
8+
fi
9+
10+
echo "Getting types for es6 promises..."
11+
npm install @types/es6-promise
12+
if [ $? -ne 0 ]; then
13+
echo -e "\033[0;31m" 1>&2 # Red
14+
echo "Couldn't get types for es6 promises."
15+
echo -e "\033[0m" 1>&2 # Normal Color
16+
exit 1
17+
fi
18+
19+
echo "Compiling down to es5..."
20+
node node_modules/typescript/bin/tsc --target es5
21+
if [ $? -ne 0 ]; then
22+
echo -e "\033[0;31m" 1>&2 # Red
23+
echo "Couldn't compile for es5."
24+
echo -e "\033[0m" 1>&2 # Normal Color
25+
npm remove @types/es6-promise
26+
exit 1
27+
fi
28+
29+
echo "Uninstalling types for es6 promises..."
30+
npm remove @types/es6-promise
31+
if [ $? -ne 0 ]; then
32+
echo -e "\033[0;33m" 1>&2 # Yellow
33+
echo "Warning: couldn't uninstall types for es6 promises"
34+
echo -e "\033[0m" 1>&2 # Normal Color
35+
fi
36+
37+
echo -e "\033[0;32m" # Green
38+
echo "Compiled to es5"
39+
echo -e "\033[0m" 1>&2 # Normal Color

scripts/generate-docs.sh

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,13 @@ if [ $? -ne 0 ]; then
6262
exit 1
6363
fi
6464

65-
echo "Getting types for es6 promises..."
66-
npm install @types/es6-promise
65+
# Compile to es5
66+
./scripts/compile_to_es5.sh
6767
if [ $? -ne 0 ]; then
68-
echo -e "\033[0;31m" 1>&2 # Red
69-
echo "Couldn't get types for es6 promises."
70-
echo -e "\033[0m" 1>&2 # Normal Color
71-
git checkout "${EXEC_BRANCH}"
72-
exit 1
73-
fi
74-
75-
echo "Compiling down to es5..."
76-
node node_modules/typescript/bin/tsc --target es5
77-
if [ $? -ne 0 ]; then
78-
echo -e "\033[0;31m" 1>&2 # Red
79-
echo "Couldn't compile for es5."
80-
echo -e "\033[0m" 1>&2 # Normal Color
81-
npm remove @types/es6-promise
8268
git checkout "${EXEC_BRANCH}"
8369
exit 1
8470
fi
8571

86-
# Remove unneeded type
87-
npm remove @types/es6-promise
88-
8972
echo "Installing the testapp..."
9073
npm run install_testapp
9174
if [ $? -ne 0 ]; then

website/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Generates the documentation for the protractor website.
66
## How to run
77

88
```shell
9+
npm run compile_to_es5
910
cd website/
1011
npm install
1112
npm run build

website/gulpfile.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,34 @@ gulp.task('clean', function(cb) {
3030

3131
// Generate the table of contents json file using Dgeni. This is output to
3232
// docgen/build/toc.json
33-
gulp.task('dgeni', function() {
33+
gulp.task('dgeni', function(done) {
3434
var packages = [require('./docgen/dgeni-config')];
3535
var dgeni = new Dgeni(packages);
3636

3737
dgeni.generate().then(function(docs) {
3838
console.log(docs.length, 'docs generated');
3939
}).then(function() {
40+
// Check that docs were generated correctly
41+
var toc = require('./docgen/build/toc.json');
42+
if (!toc || !Array.isArray(toc.items)) {
43+
return Promise.reject('Generated toc.json file is malformatted');
44+
}
45+
var isBrowser = function(item) {
46+
return item.alias == 'browser';
47+
};
48+
if (!toc.items.some(isBrowser)) {
49+
return Promise.reject('Generated toc.json missing docs for Protractor function.');
50+
}
51+
4052
// Copy files over
4153
gulp.src(['docgen/build/*.json'])
4254
.pipe(gulp.dest(paths.outputDir + '/apiDocs'));
55+
done();
56+
}).catch(function(error) {
57+
done(
58+
'Could not generate docs. ' +
59+
'Try running `npm run compile_to_es5` from Protractor\'s root folder.\n' +
60+
'Origonal Error: ' + error);
4361
});
4462
});
4563

website/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,5 @@
2929
"prestart": "npm install && npm run prepublish",
3030
"start": "gulp liveReload",
3131
"test": "node run-tests.js"
32-
},
33-
"engines": {
34-
"node": ">=4.0.0 <5.0.x"
3532
}
3633
}

website/test/e2e/api_spec.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ describe('Api', function() {
9494

9595
// Then ensure the child functions are shown.
9696
expect(apiPage.getChildFunctionNames()).toEqual([
97-
'clone', 'all', 'filter', 'get', 'first', 'last', '$$', 'count', 'locator',
98-
'then', 'each', 'map', 'reduce', 'evaluate', 'allowAnimations']);
97+
'clone', 'all', 'filter', 'get', 'first', 'last', '$$', 'count',
98+
'isPresent', 'locator', 'then', 'each', 'map', 'reduce', 'evaluate',
99+
'allowAnimations']);
99100
});
100101

101102
it('should show element functions', function() {
@@ -114,12 +115,13 @@ describe('Api', function() {
114115

115116
// Then ensure the child functions are shown.
116117
expect(apiPage.getChildFunctionNames()).toEqual([
117-
'getProcessedConfig', 'forkNewDriverInstance', 'restart',
118+
'angularAppRoot', 'waitForAngularEnabled', 'getProcessedConfig',
119+
'forkNewDriverInstance', 'restart', 'restartSync',
118120
'useAllAngular2AppRoots', 'waitForAngular', 'findElement', 'findElements',
119121
'isElementPresent', 'addMockModule', 'clearMockModules',
120122
'removeMockModule', 'getRegisteredMockModules', 'get', 'refresh',
121123
'navigate', 'setLocation', 'getLocationAbsUrl', 'debugger', 'enterRepl',
122-
'pause', 'wrapDriver']);
124+
'explore', 'pause', 'controlFlowIsEnabled']);
123125
});
124126

125127
it('should view inherited function', function() {
@@ -140,6 +142,9 @@ describe('Api', function() {
140142
'protractor objects', function() {
141143
expect(apiPage.getAdultNames().then(function(names) {
142144
return names[names.indexOf('browser') + 1];
145+
})).toBe('ExtendedWebDriver');
146+
expect(apiPage.getAdultNames().then(function(names) {
147+
return names[names.indexOf('ExtendedWebDriver') + 1];
143148
})).toBe('webdriver.WebDriver');
144149
});
145150
});

website/test/unit/api-controller-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ describe('ApiCtrl', function() {
203203
var item = scope.items[0];
204204
expect(item.title).toBe('name2');
205205
expect(item.base.name).toBe('name1');
206-
expect(item.base.items.length).toBe(1);
206+
expect(item.base.children.length).toBe(1);
207207
});
208208
});
209209

0 commit comments

Comments
 (0)