Skip to content

Commit 18318a2

Browse files
authored
fix(tests): re-enable sass/less/stylus tests (#1363)
1 parent 435cd18 commit 18318a2

File tree

6 files changed

+83
-124
lines changed

6 files changed

+83
-124
lines changed

addon/ng2/blueprints/component/files/__path__/__name__.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Component, OnInit } from '@angular/core';
1010
`,<% } else { %>
1111
templateUrl: '<%= dasherizedModuleName %>.component.html',<% } if(inlineStyle) { %>
1212
styles: []<% } else { %>
13-
styleUrls: ['<%= dasherizedModuleName %>.component.css']<% } %>
13+
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']<% } %>
1414
})
1515
export class <%= classifiedModuleName %>Component implements OnInit {
1616

addon/ng2/blueprints/component/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ module.exports = {
5454
route: options.route,
5555
isLazyRoute: !!options.isLazyRoute,
5656
isAppComponent: !!options.isAppComponent,
57-
selector: this.selector
57+
selector: this.selector,
58+
styleExt: this.styleExt
5859
};
5960
},
6061

addon/ng2/blueprints/ng2/files/__path__/app/app.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { APP_SHELL_DIRECTIVES } from '@angular/app-shell';<% } %>
1111
`,
1212
styles: [],
1313
directives: [APP_SHELL_DIRECTIVES]<% } else { %>templateUrl: 'app.component.html',
14-
styleUrls: ['app.component.css']<% } %>
14+
styleUrls: ['app.component.<%= styleExt %>']<% } %>
1515
})
1616
export class AppComponent {
1717
title = 'app works!';

addon/ng2/blueprints/ng2/files/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@
4747
"ts-node": "0.9.1",
4848
"tslint": "3.11.0",
4949
"typescript": "^1.9.0-dev.20160627-1.0",
50-
"typings": "^1.3.1"<%= stylePackage %>
50+
"typings": "^1.3.1"
5151
}
5252
}

addon/ng2/blueprints/ng2/index.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const Blueprint = require('ember-cli/lib/models/blueprint');
22
const path = require('path');
33
const stringUtils = require('ember-cli-string-utils');
44
const getFiles = Blueprint.prototype.files;
5-
const EOL = require('os').EOL;
65

76
module.exports = {
87
description: '',
@@ -29,17 +28,6 @@ module.exports = {
2928
const fullAppName = stringUtils.dasherize(options.entity.name)
3029
.replace(/-(.)/g, (_, l) => ' ' + l.toUpperCase())
3130
.replace(/^./, (l) => l.toUpperCase());
32-
33-
var stylePackage = '';
34-
switch(options.style.toLowerCase()) {
35-
case 'sass':
36-
case 'scss':
37-
stylePackage = `,${EOL} "node-sass": "3.7.0"`;
38-
break;
39-
case 'styl':
40-
stylePackage = `,${EOL} "stylus": "0.54.5"`;
41-
break;
42-
}
4331

4432
return {
4533
htmlComponentName: stringUtils.dasherize(options.entity.name),
@@ -50,8 +38,7 @@ module.exports = {
5038
prefix: options.prefix,
5139
styleExt: this.styleExt,
5240
refToTypings: refToTypings,
53-
isMobile: options.mobile,
54-
stylePackage: stylePackage
41+
isMobile: options.mobile
5542
};
5643
},
5744

tests/e2e/e2e_workflow.spec.js

+77-106
Original file line numberDiff line numberDiff line change
@@ -319,120 +319,93 @@ describe('Basic end-to-end Workflow', function () {
319319
expect(existsSync(tmpFileLocation)).to.be.equal(true);
320320
});
321321

322-
it.skip('Installs sass support successfully', function() {
322+
// Mobile mode doesn't have styles
323+
it_not_mobile('Supports scss in styleUrls', function() {
323324
this.timeout(420000);
324325

325-
sh.exec('npm install node-sass', { silent: true });
326-
return ng(['generate', 'component', 'test-component'])
327-
.then(() => {
328-
let componentPath = path.join(process.cwd(), 'src', 'app', 'test-component');
329-
let cssFile = path.join(componentPath, 'test-component.component.css');
330-
let scssFile = path.join(componentPath, 'test-component.component.scss');
331-
let scssPartialFile = path.join(componentPath, '_test-component.component.partial.scss');
332-
333-
let scssPartialExample = '.partial {\n @extend .outer;\n }';
334-
fs.writeFileSync(scssPartialFile, scssPartialExample, 'utf8');
335-
expect(existsSync(scssPartialFile)).to.be.equal(true);
336-
337-
expect(existsSync(componentPath)).to.be.equal(true);
338-
sh.mv(cssFile, scssFile);
339-
expect(existsSync(scssFile)).to.be.equal(true);
340-
expect(existsSync(cssFile)).to.be.equal(false);
341-
let scssExample = '@import "test-component.component.partial";\n\n.outer {\n .inner { background: #fff; }\n }';
342-
fs.writeFileSync(scssFile, scssExample, 'utf8');
343-
344-
sh.exec(`${ngBin} build`);
345-
let destCss = path.join(process.cwd(), 'dist', 'app', 'test-component', 'test-component.component.css');
346-
expect(existsSync(destCss)).to.be.equal(true);
347-
let contents = fs.readFileSync(destCss, 'utf8');
348-
expect(contents).to.include('.outer .inner');
349-
expect(contents).to.include('.partial .inner');
350-
351-
sh.rm('-f', destCss);
352-
process.chdir('src');
353-
sh.exec(`${ngBin} build`);
354-
expect(existsSync(destCss)).to.be.equal(true);
355-
contents = fs.readFileSync(destCss, 'utf8');
356-
expect(contents).to.include('.outer .inner');
357-
expect(contents).to.include('.partial .inner');
358-
359-
process.chdir('..');
360-
sh.exec('npm uninstall node-sass', { silent: true });
361-
});
326+
let cssFilename = 'app.component.css';
327+
let scssFilename = 'app.component.scss';
328+
let componentPath = path.join(process.cwd(), 'src', 'app');
329+
let componentFile = path.join(componentPath, 'app.component.ts');
330+
let cssFile = path.join(componentPath, cssFilename);
331+
let scssFile = path.join(componentPath, scssFilename);
332+
let scssExample = '@import "app.component.partial";\n\n.outer {\n .inner { background: #fff; }\n }';
333+
let scssPartialFile = path.join(componentPath, '_app.component.partial.scss');
334+
let scssPartialExample = '.partial {\n @extend .outer;\n }';
335+
let componentContents = fs.readFileSync(componentFile, 'utf8');
336+
337+
sh.mv(cssFile, scssFile);
338+
fs.writeFileSync(scssFile, scssExample, 'utf8');
339+
fs.writeFileSync(scssPartialFile, scssPartialExample, 'utf8');
340+
fs.writeFileSync(componentFile, componentContents.replace(new RegExp(cssFilename, 'g'), scssFilename), 'utf8');
341+
342+
sh.exec(`${ngBin} build`);
343+
let destCssBundle = path.join(process.cwd(), 'dist', 'main.bundle.js');
344+
let contents = fs.readFileSync(destCssBundle, 'utf8');
345+
expect(contents).to.include('.outer .inner');
346+
expect(contents).to.include('.partial .inner');
347+
348+
sh.mv(scssFile, cssFile);
349+
fs.writeFileSync(cssFile, '', 'utf8');
350+
fs.writeFileSync(componentFile, componentContents, 'utf8');
351+
sh.rm('-f', scssPartialFile);
362352
});
363353

364-
it.skip('Installs less support successfully', function() {
354+
// Mobile mode doesn't have styles
355+
it_not_mobile('Supports less in styleUrls', function() {
365356
this.timeout(420000);
366357

367-
sh.exec('npm install less', { silent: true });
368-
return ng(['generate', 'component', 'test-component'])
369-
.then(() => {
370-
let componentPath = path.join(process.cwd(), 'src', 'app', 'test-component');
371-
let cssFile = path.join(componentPath, 'test-component.component.css');
372-
let lessFile = path.join(componentPath, 'test-component.component.less');
373-
374-
expect(existsSync(componentPath)).to.be.equal(true);
375-
sh.mv(cssFile, lessFile);
376-
expect(existsSync(lessFile)).to.be.equal(true);
377-
expect(existsSync(cssFile)).to.be.equal(false);
378-
let lessExample = '.outer {\n .inner { background: #fff; }\n }';
379-
fs.writeFileSync(lessFile, lessExample, 'utf8');
380-
381-
sh.exec(`${ngBin} build`);
382-
let destCss = path.join(process.cwd(), 'dist', 'app', 'test-component', 'test-component.component.css');
383-
expect(existsSync(destCss)).to.be.equal(true);
384-
let contents = fs.readFileSync(destCss, 'utf8');
385-
expect(contents).to.include('.outer .inner');
386-
387-
sh.rm('-f', destCss);
388-
process.chdir('src');
389-
sh.exec(`${ngBin} build`);
390-
expect(existsSync(destCss)).to.be.equal(true);
391-
contents = fs.readFileSync(destCss, 'utf8');
392-
expect(contents).to.include('.outer .inner');
393-
394-
process.chdir('..');
395-
sh.exec('npm uninstall less', { silent: true });
396-
});
358+
let cssFilename = 'app.component.css';
359+
let lessFilename = 'app.component.less';
360+
let componentPath = path.join(process.cwd(), 'src', 'app');
361+
let componentFile = path.join(componentPath, 'app.component.ts');
362+
let cssFile = path.join(componentPath, cssFilename);
363+
let lessFile = path.join(componentPath, lessFilename);
364+
let lessExample = '.outer {\n .inner { background: #fff; }\n }';
365+
let componentContents = fs.readFileSync(componentFile, 'utf8');
366+
367+
sh.mv(cssFile, lessFile);
368+
fs.writeFileSync(lessFile, lessExample, 'utf8');
369+
fs.writeFileSync(componentFile, componentContents.replace(new RegExp(cssFilename, 'g'), lessFilename), 'utf8');
370+
371+
sh.exec(`${ngBin} build`);
372+
let destCssBundle = path.join(process.cwd(), 'dist', 'main.bundle.js');
373+
let contents = fs.readFileSync(destCssBundle, 'utf8');
374+
expect(contents).to.include('.outer .inner');
375+
376+
fs.writeFileSync(lessFile, '', 'utf8');
377+
sh.mv(lessFile, cssFile);
378+
fs.writeFileSync(componentFile, componentContents, 'utf8');
397379
});
398380

399-
it.skip('Installs stylus support successfully', function() {
381+
// Mobile mode doesn't have styles
382+
it_not_mobile('Supports stylus in styleUrls', function() {
400383
this.timeout(420000);
401384

402-
sh.exec('npm install stylus', { silent: true });
403-
return ng(['generate', 'component', 'test-component'])
404-
.then(() => {
405-
let componentPath = path.join(process.cwd(), 'src', 'app', 'test-component');
406-
let cssFile = path.join(componentPath, 'test-component.component.css');
407-
let stylusFile = path.join(componentPath, 'test-component.component.styl');
408-
409-
sh.mv(cssFile, stylusFile);
410-
expect(existsSync(stylusFile)).to.be.equal(true);
411-
expect(existsSync(cssFile)).to.be.equal(false);
412-
let stylusExample = '.outer {\n .inner { background: #fff; }\n }';
413-
fs.writeFileSync(stylusFile, stylusExample, 'utf8');
414-
415-
sh.exec(`${ngBin} build`);
416-
let destCss = path.join(process.cwd(), 'dist', 'app', 'test-component', 'test-component.component.css');
417-
expect(existsSync(destCss)).to.be.equal(true);
418-
let contents = fs.readFileSync(destCss, 'utf8');
419-
expect(contents).to.include('.outer .inner');
420-
421-
sh.rm('-f', destCss);
422-
process.chdir('src');
423-
sh.exec(`${ngBin} build`);
424-
expect(existsSync(destCss)).to.be.equal(true);
425-
contents = fs.readFileSync(destCss, 'utf8');
426-
expect(contents).to.include('.outer .inner');
427-
428-
process.chdir('..');
429-
sh.exec('npm uninstall stylus', { silent: true });
430-
});
385+
let cssFilename = 'app.component.css';
386+
let stylusFilename = 'app.component.scss';
387+
let componentPath = path.join(process.cwd(), 'src', 'app');
388+
let componentFile = path.join(componentPath, 'app.component.ts');
389+
let cssFile = path.join(componentPath, cssFilename);
390+
let stylusFile = path.join(componentPath, stylusFilename);
391+
let stylusExample = '.outer {\n .inner { background: #fff; }\n }';
392+
let componentContents = fs.readFileSync(componentFile, 'utf8');
393+
394+
sh.mv(cssFile, stylusFile);
395+
fs.writeFileSync(stylusFile, stylusExample, 'utf8');
396+
fs.writeFileSync(componentFile, componentContents.replace(new RegExp(cssFilename, 'g'), stylusFilename), 'utf8');
397+
398+
sh.exec(`${ngBin} build`);
399+
let destCssBundle = path.join(process.cwd(), 'dist', 'main.bundle.js');
400+
let contents = fs.readFileSync(destCssBundle, 'utf8');
401+
expect(contents).to.include('.outer .inner');
402+
403+
fs.writeFileSync(stylusFile, '', 'utf8');
404+
sh.mv(stylusFile, cssFile);
405+
fs.writeFileSync(componentFile, componentContents, 'utf8');
431406
});
432407

433-
// This test causes complications with path resolution in TS broccoli plugin,
434-
// and isn't mobile specific
435-
it_not_mobile('Turn on `noImplicitAny` in tsconfig.json and rebuild', function () {
408+
it('Turn on `noImplicitAny` in tsconfig.json and rebuild', function () {
436409
this.timeout(420000);
437410

438411
const configFilePath = path.join(process.cwd(), 'src', 'tsconfig.json');
@@ -443,10 +416,8 @@ describe('Basic end-to-end Workflow', function () {
443416

444417
sh.rm('-rf', path.join(process.cwd(), 'dist'));
445418

446-
return ng(['build'])
447-
.then(() => {
448-
expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true);
449-
});
419+
sh.exec(`${ngBin} build`);
420+
expect(existsSync(path.join(process.cwd(), 'dist'))).to.be.equal(true);
450421
});
451422

452423
it('Turn on path mapping in tsconfig.json and rebuild', function () {

0 commit comments

Comments
 (0)