Skip to content

Commit ce831a9

Browse files
committed
chore(snapshot): include css tests
1 parent a43980b commit ce831a9

File tree

6 files changed

+36
-201
lines changed

6 files changed

+36
-201
lines changed

config/demos/processors/demos.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
description: 'Output demos to their files on ionic-demo website',
1212
runAfter: ['files-read'],
1313
runBefore: ['processing-docs'],
14-
process: function(docs, config) {
14+
process: function(docs, config, extraData) {
1515

1616
var contentsFolder = config.rendering.contentsFolder;
1717
var assetOutputPath = '${component}/${name}/${fileName}';
@@ -23,9 +23,12 @@ module.exports = {
2323
};
2424
var transform = {
2525
'.scenario.js': function(doc) {
26-
doc.url = 'http://localhost:' + config.get('buildConfig.protractorPort') +
27-
'/' + config.versionData.current.folder +
28-
'/' + _.template(assetOutputPath, _.assign({},doc,{fileName:''}));
26+
doc.url = 'http://localhost:' +
27+
config.get('buildConfig.protractorPort') + path.join(
28+
config.demoFolderPrefix || '',
29+
config.versionData.current.folder,
30+
_.template(assetOutputPath, _.assign({},doc,{fileName:''}))
31+
);
2932
return doc;
3033
}
3134
};
@@ -118,6 +121,8 @@ module.exports = {
118121
outputPath: path.join(contentsFolder, 'index-ionic-demo-app.js')
119122
});
120123

124+
extraData.demoFolderPrefix = config.get('demoFolderPrefix');
125+
121126
return pages;
122127
}
123128
};

config/demos/templates/index.template.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
6-
<link rel="stylesheet" href="/{$ version.current.folder $}/ionic/css/ionic.min.css">
7-
<script src="/{$ version.current.folder $}/ionic/js/ionic.bundle.min.js"></script>
8-
<script src="/{$ version.current.folder $}/pages-data.js"></script>
6+
<link rel="stylesheet" href="{$ demoFolderPrefix $}/{$ version.current.folder $}/ionic/css/ionic.min.css">
7+
<script src="{$ demoFolderPrefix $}/{$ version.current.folder $}/ionic/js/ionic.bundle.min.js"></script>
8+
<script src="{$ demoFolderPrefix $}/{$ version.current.folder $}/pages-data.js"></script>
99

1010
{% for file in doc.demoData.files.css %}
1111
<link rel="stylesheet" href="{$ file.fileName $}">

config/gulp-tasks/test.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ var cp = require('child_process');
55
var gutil = require('gulp-util');
66
var http = require('http');
77
var karma = require('karma').server;
8+
var path = require('canonical-path');
89
var uuid = require('node-uuid');
910

11+
var projectRoot = path.resolve(__dirname, '../..');
12+
1013
var karmaConf = require('../karma.conf.js');
1114
var karmaSauceConf = require('../karma-sauce.conf.js');
1215

@@ -62,7 +65,7 @@ module.exports = function(gulp, argv) {
6265
*/
6366
var protractorHttpServer;
6467
gulp.task('protractor-server', function() {
65-
var app = connect().use(connect.static(__dirname + '/../../dist/ionic-demo'));
68+
var app = connect().use(connect.static(projectRoot));
6669
protractorHttpServer = http.createServer(app).listen(buildConfig.protractorPort);
6770
});
6871

@@ -105,7 +108,9 @@ module.exports = function(gulp, argv) {
105108
}
106109

107110
function protractor(done, args) {
108-
var child = cp.spawn('node', [__dirname+'/../../node_modules/.bin/protractor'].concat(args), {
111+
var child = cp.spawn('node', [
112+
path.resolve(projectRoot, 'node_modules/.bin/protractor')
113+
].concat(args), {
109114
stdio: [process.stdin, process.stdout, 'pipe']
110115
});
111116

config/protractor.conf.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
var buildConfig = require('./build.config');
2+
var path = require('canonical-path');
3+
var projectRoot = path.resolve(__dirname, '..');
24

35
exports.config = {
46

57
// Spec patterns are relative to the location of the spec file. They may
68
// include glob patterns.
7-
specs: [__dirname + '/../dist/ionic-demo/nightly/**/*.scenario.js'],
9+
specs: [
10+
path.resolve(projectRoot, 'test/css/**/*.scenario.js'),
11+
path.resolve(projectRoot, 'dist/ionic-demo/**/*.scenario.js'),
12+
],
813

914
// Options to be passed to Jasmine-node.
1015
jasmineNodeOpts: {

gulpfile.js

+5-182
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ var argv = require('minimist')(process.argv.slice(2));
99
var _ = require('lodash');
1010
var buildConfig = require('./config/build.config.js');
1111
var changelog = require('conventional-changelog');
12-
var dgeni = require('dgeni');
1312
var es = require('event-stream');
14-
var htmlparser = require('htmlparser2');
1513
var irc = require('ircb');
16-
var lunr = require('lunr');
1714
var marked = require('marked');
1815
var mkdirp = require('mkdirp');
1916
var twitter = require('node-twitter-api');
20-
var yaml = require('js-yaml');
2117

2218
var cp = require('child_process');
2319
var fs = require('fs');
@@ -50,6 +46,11 @@ if (IS_RELEASE_BUILD) {
5046
*/
5147
require('./config/gulp-tasks/test')(gulp, argv);
5248

49+
/**
50+
* Load Docs Tasks
51+
*/
52+
require('./config/gulp-tasks/docs')(gulp, argv);
53+
5354
if (argv.dist) {
5455
buildConfig.dist = argv.dist;
5556
}
@@ -58,53 +59,6 @@ gulp.task('default', ['build']);
5859
gulp.task('build', ['bundle', 'sass']);
5960
gulp.task('validate', ['jshint', 'ddescribe-iit', 'karma']);
6061

61-
gulp.task('docs', function() {
62-
var docVersion = argv['doc-version'] || 'nightly';
63-
if (docVersion != 'nightly' && !semver.valid(docVersion)) {
64-
console.log('Usage: gulp docs --doc-version=(nightly|versionName)');
65-
return process.exit(1);
66-
}
67-
68-
var config = dgeni.loadConfig(path.join(__dirname, '/config/docs/docs.config.js'));
69-
config.set('currentVersion', docVersion);
70-
config.set(
71-
'rendering.outputFolder',
72-
argv.dist ? argv.dist : path.resolve(__dirname, buildConfig.dist, 'ionic-site')
73-
);
74-
75-
return dgeni.generator(config)().then(function() {
76-
gutil.log('Docs for', gutil.colors.cyan(docVersion), 'generated!');
77-
});
78-
});
79-
80-
gulp.task('demos', function(done) {
81-
var demoVersion = argv['demo-version'] || 'nightly';
82-
if (demoVersion != 'nightly' && !semver.valid(demoVersion)) {
83-
console.log('Usage: gulp docs --doc-version=(nightly|versionName)');
84-
return process.exit(1);
85-
}
86-
87-
var config = dgeni.loadConfig(path.join(__dirname, '/config/demos/demos.config.js'));
88-
config.set('currentVersion', demoVersion);
89-
config.set('dist', buildConfig.dist);
90-
config.set(
91-
'rendering.outputFolder',
92-
argv.dist ? argv.dist : path.resolve(__dirname, buildConfig.dist, 'ionic-demo')
93-
);
94-
95-
dgeni.generator(config)().then(function() {
96-
gutil.log('Demos for', gutil.colors.cyan(demoVersion), 'generated!');
97-
gutil.log('Building ionic into demo folder...');
98-
cp.spawn('node', [
99-
__dirname + '/node_modules/.bin/gulp',
100-
'build',
101-
IS_RELEASE_BUILD ? '--release' : '--no-release',
102-
'--dist=' + config.rendering.outputFolder + '/' +
103-
config.rendering.contentsFolder + '/ionic'
104-
])
105-
.on('exit', done);
106-
});
107-
});
10862

10963
var IS_WATCH = false;
11064
gulp.task('watch', ['build'], function() {
@@ -288,137 +242,6 @@ gulp.task('release-irc', function(done) {
288242
});
289243
});
290244

291-
gulp.task('docs-index', function() {
292-
var idx = lunr(function() {
293-
this.field('path');
294-
this.field('title', {boost: 10});
295-
this.field('body');
296-
this.ref('id');
297-
});
298-
var ref = {};
299-
var refId = 0;
300-
301-
function addToIndex(path, title, layout, body) {
302-
// Add the data to the indexer and ref object
303-
idx.add({'path': path, 'body': body, 'title': title, id: refId});
304-
ref[refId] = {'p': path, 't': title, 'l': layout};
305-
refId++;
306-
}
307-
308-
return gulp.src([
309-
'temp/ionic-site/docs/{components,guide,api,overview}/**/*.{md,html,markdown}',
310-
'temp/ionic-site/docs/index.html',
311-
'temp/ionic-site/getting-started/index.html',
312-
'temp/ionic-site/tutorials/**/*.{md,html,markdown}',
313-
'temp/ionic-site/_posts/**/*.{md,html,markdown}'
314-
])
315-
.pipe(es.map(function(file, callback) {
316-
//docs for gulp file objects: https://github.com/wearefractal/vinyl
317-
var contents = file.contents.toString(); //was buffer
318-
319-
// Grab relative path from ionic-site root
320-
var relpath = file.path.replace(/^.*?temp\/ionic-site\//, '');
321-
322-
// Read out the yaml portion of the Jekyll file
323-
var yamlStartIndex = contents.indexOf('---');
324-
325-
if (yamlStartIndex === -1) {
326-
return callback();
327-
}
328-
329-
// read Jekyll's page yaml variables at the top of the file
330-
var yamlEndIndex = contents.indexOf('---', yamlStartIndex+3); //starting from start
331-
var yamlRaw = contents.substring(yamlStartIndex+3, yamlEndIndex);
332-
333-
var pageData = yaml.safeLoad(yamlRaw);
334-
if(!pageData.title || !pageData.layout) {
335-
return callback();
336-
}
337-
338-
// manually set to not be searchable, or for a blog post, manually set to be searchable
339-
if(pageData.searchable === false || (pageData.layout == 'post' && pageData.searchable !== true)) {
340-
return callback();
341-
}
342-
343-
// clean up some content so code variables are searchable too
344-
contents = contents.substring(yamlEndIndex+3);
345-
contents = contents.replace(/<code?>/gi, '');
346-
contents = contents.replace(/<\/code>/gi, '');
347-
contents = contents.replace(/<code?></gi, '');
348-
contents = contents.replace(/><\/code>/gi, '');
349-
contents = contents.replace(/`</gi, '');
350-
contents = contents.replace(/>`/gi, '');
351-
352-
// create a clean path to the URL
353-
var path = '/' + relpath.replace('index.md', '')
354-
.replace('index.html', '')
355-
.replace('.md', '.html')
356-
.replace('.markdown', '.html');
357-
if(pageData.layout == 'post') {
358-
path = '/blog/' + path.substring(19).replace('.html', '/');
359-
}
360-
361-
var parser;
362-
if(pageData.search_sections === true) {
363-
// each section within the content should be its own search result
364-
var section = { body: '', title: '' };
365-
var isTitleOpen = false;
366-
367-
parser = new htmlparser.Parser({
368-
ontext: function(text){
369-
if(isTitleOpen) {
370-
section.title += text; // get the title of this section
371-
} else {
372-
section.body += text.replace(/{%.*%}/, '', 'g'); // Ignore any Jekyll expressions
373-
}
374-
},
375-
onopentag: function(name, attrs) {
376-
if(name == 'section' && attrs.id) {
377-
// start building new section data
378-
section = { body: '', path: path + '#' + attrs.id, title: '' };
379-
} else if( (name == 'h1' || name == 'h2' || name == 'h3') && attrs.class == 'title') {
380-
isTitleOpen = true; // the next text will be this sections title
381-
}
382-
},
383-
onclosetag: function(name) {
384-
if(name == 'section') {
385-
// section closed, index this section then clear it out
386-
addToIndex(section.path, section.title, pageData.layout, section.body);
387-
section = { body: '', title: '' };
388-
} else if( (name == 'h1' || name == 'h2' || name == 'h3') && isTitleOpen) {
389-
isTitleOpen = false;
390-
}
391-
}
392-
});
393-
parser.write(contents);
394-
parser.end();
395-
396-
} else {
397-
// index the entire page
398-
var body = '';
399-
parser = new htmlparser.Parser({
400-
ontext: function(text){
401-
body += text.replace(/{%.*%}/, '', 'g'); // Ignore any Jekyll expressions
402-
}
403-
});
404-
parser.write(contents);
405-
parser.end();
406-
407-
addToIndex(path, pageData.title, pageData.layout, body);
408-
}
409-
410-
callback();
411-
412-
})).on('end', function() {
413-
// Write out as one json file
414-
mkdirp.sync('temp/ionic-site/data');
415-
fs.writeFileSync(
416-
'temp/ionic-site/data/index.json',
417-
JSON.stringify({'ref': ref, 'index': idx.toJSON()})
418-
);
419-
});
420-
});
421-
422245
function notContains(disallowed) {
423246
disallowed = disallowed || [];
424247

test/css/test.scenario.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
describe('css snapshot', function() {
22

3-
var tests = [
3+
[
44
'bars-clear',
55
'buttons',
66
'cards-header-footer',
@@ -22,15 +22,12 @@ describe('css snapshot', function() {
2222
'input-toogle',
2323
'list',
2424
'modals',
25-
];
26-
27-
for(var x=0; x<tests.length; x++) {
28-
(function(){
29-
var testId = tests[x];
30-
it(testId, function() {
25+
].forEach(function(testId) {
26+
describe(testId, function() {
27+
it('init', function() {
3128
browser.get('http://localhost:8876/test/css/' + testId + '.html');
3229
});
33-
})();
34-
}
30+
});
31+
});
3532

3633
});

0 commit comments

Comments
 (0)