Skip to content

Commit 96ceca9

Browse files
committed
Merge pull request #171 from sourcejs/0.5.5-dev
0.5.5
2 parents 2b9fabe + 7c2d698 commit 96ceca9

14 files changed

+338
-26
lines changed

Gruntfile.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ global.pathToApp = pathToApp;
77
var loadOptions = require('./core/loadOptions');
88

99
module.exports = function(grunt) {
10+
var appPort = grunt.option('app-port') || 8080;
11+
1012
// load all grunt tasks matching the `grunt-*` pattern
1113
require('load-grunt-tasks')(grunt);
1214

@@ -177,11 +179,18 @@ module.exports = function(grunt) {
177179

178180
mochaTest: {
179181
test: {
180-
src: ['test/**/*.js']
182+
src: ['test/specs/**/*.js']
181183
},
182184
noApp: {
183185
src: ['test/specs/lib/**/*.js']
184186
}
187+
},
188+
189+
casperjs: {
190+
options: {
191+
casperjsOptions: ['--app-port='+appPort]
192+
},
193+
files: ['test/casperjs/**/*.js']
185194
}
186195
});
187196

@@ -286,6 +295,11 @@ module.exports = function(grunt) {
286295
]);
287296

288297
grunt.registerTask('ci-post-run', [
298+
'test',
299+
'test-func'
300+
]);
301+
302+
grunt.registerTask('ci-post-run-win', [
289303
'test'
290304
]);
291305

@@ -297,14 +311,23 @@ module.exports = function(grunt) {
297311

298312
// Test task. Execute with running app
299313
grunt.registerTask('test', 'Run ALL tests or specified by second param', function () {
314+
// if custom mask set - `grunt test --spec=test/specs/middleware/**/*.js`
300315
var spec = grunt.option('spec');
301-
302316
if (spec) {
303-
// if custom mask set - `grunt test --spec=test/specs/middleware/**/*.js`
304317
grunt.config.set('mochaTest.test.src', [spec]);
305-
grunt.task.run('mochaTest');
306-
} else {
307-
grunt.task.run('mochaTest');
308318
}
319+
320+
grunt.task.run('mochaTest');
321+
});
322+
323+
// Test task. Execute with running app
324+
grunt.registerTask('test-func', 'Run ALL functional tests or specified by second param', function () {
325+
// if custom mask set - `grunt test --spec=test/specs/middleware/**/*.js`
326+
var spec = grunt.option('spec');
327+
if (spec) {
328+
grunt.config.set('casperjs.files', [spec]);
329+
}
330+
331+
grunt.task.run('casperjs');
309332
});
310333
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ If you notice some bugs, or need to help finding a better solution in your proce
5252
[Materials for presentations](https://github.com/sourcejs/pres).
5353

5454
## Updates
55+
* 16.08.15 [0.5.5](https://github.com/sourcejs/Source/releases/tag/0.5.5) and [0.5.5-no-jsdom](https://github.com/sourcejs/Source/releases/tag/0.5.5-no-jsdom) patch release with `<markdown>` tag fix and set of functional tests
5556
* 15.08.15 [0.5.4](https://github.com/sourcejs/Source/releases/tag/0.5.4) and [0.5.4-no-jsdom](https://github.com/sourcejs/Source/releases/tag/0.5.4-no-jsdom) with middleware loader, relative paths in navigation support and other improvements
5657
* 28.05.15 [0.5.3](https://github.com/sourcejs/Source/releases/tag/0.5.3) context options support, source-as-npm package, CI integration, watcher stability improvements and other great features
5758
* 28.05.15 [0.5.3-no-jsdom](https://github.com/sourcejs/Source/releases/tag/0.5.3-no-jsdom) special release without JSDom for Windows users

app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ commander
3333
.option('--html', 'Turn on HTML parser on app start (requires installed and enabled parser).')
3434
.option('--test', 'Run app with tests.')
3535
.option('--no-watch', 'Run with disabled watcher.')
36+
.option('--post-grunt [string]', 'Define Grunt command to run after app start', 'ci-post-run')
3637
.parse(process.argv);
3738

3839
global.commander = commander;
@@ -230,7 +231,7 @@ if (!module.parent) {
230231
if (commander.test) {
231232
var spawn = require('cross-spawn');
232233

233-
spawn('./node_modules/grunt-cli/bin/grunt', ['ci-post-run'], {stdio: 'inherit'})
234+
spawn('./node_modules/grunt-cli/bin/grunt', [commander.postGrunt, '--port='+port], {stdio: 'inherit'})
234235
.on('close', function (code) {
235236
if (code === 0) {
236237
log.info('Test successful');

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ before_test: "git clone https://github.com/sourcejs/init.git user"
1616

1717
test_script:
1818
- node --version && npm --version
19-
- ps: "npm run ci-test # PowerShell" # Pass comment to PS for easier debugging
20-
- cmd: "npm run ci-test-nw" # Run without watch because of CI bug
19+
- ps: "npm run ci-test-win # PowerShell" # Pass comment to PS for easier debugging
20+
- cmd: "npm run ci-test-win" # Run without watch because of CI bug
2121

2222
matrix:
2323
fast_finish: true

assets/js/modules/codeSource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ define([
222222
};
223223

224224
if ($('[class*="src-"]:not(.source_visible)')[0]) {
225-
innerNavigation.addMenuItem(RES_TOGGLER_SHOW_CODE, showAllCode, hideAllCode);
225+
innerNavigation.addMenuItem(RES_TOGGLER_SHOW_CODE, showAllCode, hideAllCode, 'source_source-code_action-item');
226226
}
227227

228228
showStaticCode();

assets/js/modules/parseFileTree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ define([
1717
], function ($, module, data, allSpecs) {
1818

1919
function ParseFileTree() {
20-
this.json = $.parseJSON(data.toString());
20+
this.json = JSON.parse(data);
2121
}
2222

2323
ParseFileTree.prototype = module.createInstance();

assets/js/modules/search.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ Search.prototype.constructor = Search;
3939
Search.prototype = module.createInstance();
4040

4141
Search.prototype.init = function() {
42+
var _this = this;
43+
4244
this.activated = false;
4345
this.targetField = $('#livesearch');
4446
this.header = $('.source_header');
4547

4648
this.prepareAutoCompleteData();
4749
this.initSearchField();
50+
51+
setTimeout(function() {
52+
_this.targetField.attr('data-initialized', 'true');
53+
}, 1);
4854
};
4955

5056
Search.prototype.prepareAutoCompleteData = function() {

docs/base/readme.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ To set-up a new engine instance chose the first option `Init SourceJS in this fo
2626
To install SourceJS as a NPM package, first clone clean `user` configuration folder and then execute `npm install`.
2727

2828
```html
29-
git clone https://github.com/sourcejs/init.git my-sourcejs && cd my-sourcejs
29+
git clone https://github.com/sourcejs/init.git -b npm my-sourcejs && cd my-sourcejs
3030
npm install sourcejs --save
31-
node ./node_modules/sourcejs/app
31+
npm start
3232
```
3333

3434
Starting from 0.6.0 we're planning to change official install path to one with NPM packages. Yeoman generator will be also replaced by [sourcejs-cli](https://github.com/sourcejs/sourcejs-cli) with commands like `run`, `install` (plugin), `init`, `create`.
@@ -37,40 +37,40 @@ Starting from 0.6.0 we're planning to change official install path to one with N
3737

3838
If you're running Windows and have some issues with [JSDom](https://github.com/tmpvar/jsdom) dependencies compilation, please check this [topic](https://github.com/sourcejs/Source/issues/23).
3939

40-
Alternatively with 0.5.4 we prepared a special build without JSDom, until it's full removal from core at 0.6.0.
40+
Alternatively with 0.5.5 we prepared a special build without JSDom, until it's full removal from core at 0.6.0.
4141

4242
```html
4343
npm install -g yo generator-sourcejs
4444
mkdir sourcejs && cd sourcejs
45-
yo sourcejs --branch 0.5.4-no-jsdom
45+
yo sourcejs --branch 0.5.5-no-jsdom
4646
```
4747

4848
Please note that Clarify feature is not available in `no-jsdom` version. If you had generator installed before, run `npm update -g generator-sourcejs` (v.0.4.2+ required).
4949

5050
And installing same build from NPM:
5151

5252
```html
53-
git clone https://github.com/sourcejs/init.git my-sourcejs && cd my-sourcejs
54-
npm install [email protected].4-no-jsdom --save
55-
node .\node_modules\sourcejs\app
53+
git clone https://github.com/sourcejs/init.git -b npm my-sourcejs && cd my-sourcejs
54+
npm install [email protected].5-no-jsdom --save
55+
npm start
5656
```
5757

5858
## Commands
5959

6060
### Run
6161

62-
Installation wizard will offer to start SourceJS right after initialization. To run it manually, trigger this command in newly created folder:
62+
Installation wizard will offer to start SourceJS right after initialization. To run it manually, trigger this command in newly created folder with SourceJS app:
6363

6464
```html
65-
node app
65+
npm start
6666
```
6767

68-
To set an alternative server port, pass `-p 8081` option.
68+
To set an alternative server port, pass `-- -p 8081` option.
6969

7070
Other configuration arguments are described in the help section:
7171

7272
```html
73-
node app -h
73+
npm start -- -h
7474
```
7575

7676
### Build
@@ -88,7 +88,7 @@ It will trigger `npm i` and `grunt default` commands for updating dependencies a
8888
For updating SourceJS to a newer version, just pull the latest changes and trigger build:
8989

9090
```html
91-
git pull && npm install
91+
git pull && npm run build
9292
```
9393

9494
## Creating First Spec

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sourcejs",
33
"description": "Living Style Guide Engine for Managing and Developing Front-end Components.",
44
"author": "SourceJS",
5-
"version": "0.5.4",
5+
"version": "0.5.5",
66
"license": "MIT",
77
"repository": {
88
"type": "git",
@@ -53,16 +53,17 @@
5353
"tinyforever": "0.0.3"
5454
},
5555
"scripts": {
56-
"postinstall": "grunt update && node ./core/postInstall",
56+
"postinstall": "node ./core/postInstall && grunt update",
5757
"build": "npm i",
5858
"start": "node app",
5959
"test": "grunt ci-pre-run && node app.js --test",
6060
"ci-test": "grunt ci-pre-run && node app.js --test --log trace",
61-
"ci-test-nw": "grunt ci-pre-run && node app.js --test --log trace --no-watch"
61+
"ci-test-win": "grunt ci-pre-run && node app.js --post-grunt ci-post-run-win --test --log trace --no-watch"
6262
},
6363
"devDependencies": {
6464
"assert": "~1.1.1",
6565
"cross-spawn": "^0.4.0",
66+
"grunt-casperjs": "^2.1.0",
6667
"grunt-mocha-test": "^0.12.4",
6768
"mocha": "^2.0.1",
6869
"should": "~4.0.4",

test/casperjs/common.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var appPort = casper.cli.get("app-port") || 8080;
2+
var url = 'http://127.0.0.1:' + appPort;
3+
4+
casper.options.viewportSize = {width: 1024, height: 768};
5+
6+
var urlsToCheck = [
7+
url,
8+
url + '/docs/spec/',
9+
url + '/docs/'
10+
];
11+
12+
var error = {};
13+
14+
casper.on("page.error", function(msg, trace) {
15+
error.msg = msg;
16+
17+
this.echo("Error: " + msg, "ERROR");
18+
this.echo("file: " + trace[0].file, "WARNING");
19+
this.echo("line: " + trace[0].line, "WARNING");
20+
this.echo("function: " + trace[0]["function"], "WARNING");
21+
});
22+
23+
urlsToCheck.forEach(function(item){
24+
casper.test.begin('Check availability and JS errors on ' + item, 2, function(test) {
25+
error = {};
26+
27+
casper.start(item).then(function(response) {
28+
29+
casper.wait(500, function(){
30+
// Slow down a bit, because of strange API bug
31+
});
32+
33+
if (response.status !== 200) {
34+
test.fail("Page load error, expected status 200, got " + response.status);
35+
} else {
36+
test.pass("Status 200 OK");
37+
}
38+
}).then(function() {
39+
if (typeof error.msg === 'string') {
40+
test.fail("JS errors found: "+ error.msg);
41+
} else {
42+
test.pass("No JS errors");
43+
}
44+
45+
}).run(function() { test.done() }).clear();
46+
});
47+
});

test/casperjs/globalNav.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var appPort = casper.cli.get('app-port') || 8080;
2+
var url = 'http://127.0.0.1:' + appPort + '/docs/';
3+
4+
casper.options.viewportSize = {width: 1024, height: 768};
5+
6+
casper.test.begin('Check navigaton page', 3, function suite(test) {
7+
casper.start(url).then(function() {
8+
var _this = this;
9+
var nav = '.source_catalog_list .source_catalog_list_i';
10+
11+
this.waitForSelector(nav,
12+
function pass() {
13+
test.assertEval(function (nav) {
14+
return document.querySelectorAll(nav).length > 5;
15+
}, 'Should have more than 5 nav items', [nav]);
16+
17+
test.assertEval(function (nav) {
18+
return !!document.querySelector(nav + ' .source_catalog_a[href="/docs/base"]') &&
19+
!!document.querySelector(nav + ' .source_catalog_a[href="/docs/clarify"]') &&
20+
!!document.querySelector(nav + ' .source_catalog_a[href="/docs/starting"]');
21+
}, 'Right nav items in set', [nav]);
22+
},
23+
function fail() {
24+
test.fail(nav);
25+
}
26+
);
27+
28+
}).then(function(){
29+
this.click('.source_catalog_image-tumbler');
30+
test.assertExists('.source_catalog.__show-preview', 'Show preview toggled');
31+
32+
}).run(function() { test.done() }).clear();
33+
});

test/casperjs/search.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
var appPort = casper.cli.get('app-port') || 8080;
2+
var url = 'http://127.0.0.1:' + appPort;
3+
4+
casper.options.viewportSize = {width: 1024, height: 768};
5+
6+
casper.test.begin('Checking search', 3, function suite(test) {
7+
casper.start(url).then(function() {
8+
var _this = this;
9+
var input = '.source_search .source_search_it';
10+
var autoComplete = '.autocomplete-wrapper .autocomplete-suggestion:first-child a';
11+
var searchField = '.source_search_it[data-initialized]';
12+
13+
test.assertExists(input, 'Search input exists');
14+
15+
this.waitForSelector(searchField,
16+
function pass() {
17+
casper.sendKeys(searchField, 'main', {keepFocus: true});
18+
19+
_this.waitForSelector(autoComplete,
20+
function pass() {
21+
this.click(autoComplete);
22+
},
23+
function fail() {
24+
test.fail(autoComplete);
25+
}
26+
);
27+
},
28+
function fail() {
29+
test.fail(searchField);
30+
}
31+
);
32+
33+
}).then(function() {
34+
35+
this.waitFor(
36+
function check() {
37+
return (this.getCurrentUrl() === url+'/docs/base/');
38+
},
39+
function then() { // step to execute when check() is ok
40+
test.assertExists('.source_main > h1', 'Spec header exists');
41+
42+
test.assertEquals(this.getCurrentUrl(), url+'/docs/base/', 'New page URL is right')
43+
},
44+
function timeout() { // step to execute if check has failed
45+
this.echo('Failed to navigate to search result');
46+
}
47+
);
48+
49+
}).run(function() { test.done() }).clear();
50+
});

0 commit comments

Comments
 (0)