Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit da5b2b0

Browse files
rkjchirayuk
authored andcommitted
test: add test for template_cache_generator css rewriting
It use simple sed script to showcase integration is working. Test runs only if sed is present on the running system. The test uses css with simple rules that are getting traslated for RTL locales. Closes dart-archive#1052
1 parent 34e2259 commit da5b2b0

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

test/io/template_cache_generator_spec.dart

+39
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,45 @@ void main() {
7070
});
7171
});
7272

73+
if (new File("/bin/sed").existsSync()) {
74+
it('should correctly use simple sed rewritter to fake css mirroring', () {
75+
var tmpDir = Directory.systemTemp.createTempSync();
76+
Future flush;
77+
try {
78+
flush = generator.main([
79+
'--out=${tmpDir.path}/generated.dart',
80+
'--url-rewrites=/test/io/test_files,rewritten',
81+
'--css-rewriter=test/io/test_files/rewritter.sh',
82+
'test/io/test_files/cssUrls/main.dart',
83+
'generated']);
84+
} catch(_) {
85+
tmpDir.deleteSync(recursive: true);
86+
rethrow;
87+
}
88+
return flush.then((_) {
89+
expect(new File('${tmpDir.path}/generated.dart').readAsStringSync(),
90+
'''// GENERATED, DO NOT EDIT!
91+
library generated;
7392
93+
import 'package:angular/angular.dart';
94+
95+
primeTemplateCache(TemplateCache tc) {
96+
tc.put("rewritten/cssUrls/four.css", new HttpResponse(200, r""".float-right {
97+
float: right;
98+
}
99+
.right-margin {
100+
margin-right: 20px;
101+
}
102+
103+
"""));
104+
tc.put("rewritten/cssUrls/one.css", new HttpResponse(200, r"""body {}"""));
105+
tc.put("rewritten/cssUrls/three.css", new HttpResponse(200, r"""body {}"""));
106+
tc.put("rewritten/cssUrls/two.css", new HttpResponse(200, r"""body {}"""));
107+
}''');
108+
}).whenComplete(() {
109+
tmpDir.deleteSync(recursive: true);
110+
});
111+
});
112+
}
74113
});
75114
}

test/io/test_files/cssUrls/four.css

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.float-left {
2+
float: left;
3+
}
4+
.left-margin {
5+
margin-left: 20px;
6+
}
7+

test/io/test_files/rewritter.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
/bin/sed 's/left/right/g'

0 commit comments

Comments
 (0)