-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Workiva/updates
CP-1328 Move dart_to_js_script_rewriter to workiva ownership
- Loading branch information
Showing
10 changed files
with
213 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
.pub/ | ||
.settings/ | ||
build | ||
coverage/ | ||
packages | ||
pubspec.lock | ||
.packages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: dart | ||
dart: | ||
- stable | ||
script: | ||
- pub run dart_dev format --check | ||
- pub run dart_dev analyze | ||
- pub run dart_dev test | ||
- pub run dart_dev coverage --no-html | ||
- bash <(curl -s https://codecov.io/bash) -f coverage/coverage.lcov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# dart_to_js_script_rewriter | ||
|
||
<a href="https://pub.dartlang.org/packages/dart_to_js_script_rewriter"><img src="https://img.shields.io/pub/v/dart_to_js_script_rewriter.svg" alt="Pub" /></a> | ||
<a href="https://travis-ci.org/Workiva/dart_to_js_script_rewriter"><img src="https://travis-ci.org/Workiva/dart_to_js_script_rewriter.svg?branch=travis-ci" alt="Build Status" /></a> | ||
<a href="http://codecov.io/github/Workiva/dart_to_js_script_rewriter?branch=master"><img src="http://codecov.io/github/Workiva/dart_to_js_script_rewriter/coverage.svg?branch=master" alt="codecov.io" /></a> | ||
|
||
|
||
A pub transformer that rewrites Dart script tags to | ||
JavaScript script tags, eliminating | ||
404s and speeding up initial loads. | ||
|
@@ -71,5 +76,7 @@ See the [pub docs][pubdocs] for more on modes. | |
|
||
Please use the [issue tracker][issues]. | ||
|
||
[issues]: https://github.com/sethladd/dart_to_js_script_rewriter/issues | ||
[issues]: https://github.com/Workiva/dart_to_js_script_rewriter/issues | ||
[pubdocs]: https://www.dartlang.org/tools/pub/ | ||
|
||
Thanks to Seth Ladd, <[email protected]>, for creating the original version of this [library](https://github.com/sethladd/dart_to_js_script_rewriter). |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,28 @@ name: dart_to_js_script_rewriter | |
description: Replaces Dart script tags with JavaScript script tags, | ||
speeding up initial loads and reducing 404s. Use when | ||
ready to deploy. | ||
author: Seth Ladd <[email protected]> | ||
author: | ||
- Seth Ladd <[email protected]> | ||
- Workiva Client Platform Team <[email protected]> | ||
- Dustin Lessard <[email protected]> | ||
- Evan Weible <[email protected]> | ||
- Jay Udey <[email protected]> | ||
- Max Peterson <[email protected]> | ||
- Trent Grover <[email protected]> | ||
version: 0.1.0+4 | ||
homepage: https://github.com/sethladd/dart_to_js_script_rewriter | ||
homepage: https://github.com/Workiva/dart_to_js_script_rewriter | ||
dependencies: | ||
barback: ">=0.15.0 <0.16.0" | ||
html: ">=0.12.0 <0.13.0" | ||
dev_dependencies: | ||
browser: any | ||
coverage: "^0.7.2" | ||
dart_style: ">=0.1.8 <0.3.0" | ||
dartdoc: "^0.4.0" | ||
dart_dev: "^1.0.6" | ||
mockito: any | ||
test: any | ||
transformers: | ||
- dart_to_js_script_rewriter | ||
- test/pub_serve: | ||
$include: test/**_test{.*,}.dart |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
@TestOn('vm') | ||
library dart_to_js_script_rewriter.test.dart_to_js_script_rewriter_test; | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:barback/barback.dart' | ||
show Asset, AssetId, BarbackMode, BarbackSettings; | ||
import 'package:html/dom.dart' show Document; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'package:dart_to_js_script_rewriter/dart_to_js_script_rewriter.dart'; | ||
import 'transformer_mocks.dart'; | ||
|
||
void main() { | ||
group('dart_to_js_script_rewriter', () { | ||
test('removeDartDotJsTags', () { | ||
DartToJsScriptRewriter transformer = _transformer(); | ||
Document document = new Document.html(_html); | ||
transformer.removeDartDotJsTags(document); | ||
var dartJsScripts = document.querySelectorAll('script').where((tag) { | ||
Map attrs = tag.attributes; | ||
return attrs['src'] != null && attrs['src'].endsWith('/dart.js'); | ||
}); | ||
expect(dartJsScripts, isEmpty); | ||
}); | ||
|
||
test('rewriteDartTags', () { | ||
DartToJsScriptRewriter transformer = _transformer(); | ||
Document document = new Document.html(_html); | ||
transformer.rewriteDartTags(document); | ||
var dartJsScripts = document.querySelectorAll('script').where((tag) { | ||
Map attrs = tag.attributes; | ||
return attrs['type'] == 'application/dart' && attrs['src'] != null; | ||
}); | ||
expect(dartJsScripts, isEmpty); | ||
}); | ||
|
||
test('allowedExtensions', () { | ||
expect( | ||
new DartToJsScriptRewriter.asPlugin( | ||
new BarbackSettings(const {}, BarbackMode.RELEASE)) | ||
.allowedExtensions, | ||
equals('.html')); | ||
}); | ||
|
||
group('apply()', () { | ||
BarbackSettings configuration; | ||
final Matcher isHtmlFile = | ||
predicate((Asset asset) => asset.id.extension == '.html'); | ||
DartToJsScriptRewriter transformer; | ||
|
||
test('when run in release mode', () async { | ||
configuration = new BarbackSettings(const {}, BarbackMode.RELEASE); | ||
transformer = new DartToJsScriptRewriter.asPlugin(configuration); | ||
AssetId fakeInputFileAssetId = | ||
new AssetId('testid', 'test/test_data/test_file.html'); | ||
|
||
MockAsset inputFile; | ||
MockTransform mockTransform; | ||
|
||
String transformedFile; | ||
|
||
inputFile = new MockAsset(); | ||
mockTransform = new MockTransform(); | ||
|
||
when(inputFile.id).thenReturn(fakeInputFileAssetId); | ||
when(inputFile.readAsString()).thenReturn( | ||
new File.fromUri(Uri.parse('test/test_data/test_file.html')) | ||
.readAsString()); | ||
|
||
when(mockTransform.primaryInput).thenReturn(inputFile); | ||
when(mockTransform.readInputAsString(fakeInputFileAssetId)) | ||
.thenAnswer((_) { | ||
return new File.fromUri(Uri.parse('test/test_data/test_file.html')) | ||
.readAsString(); | ||
}); | ||
|
||
await transformer.apply(mockTransform); | ||
|
||
Asset fileAsset = | ||
verify(mockTransform.addOutput(captureThat(isHtmlFile))) | ||
.captured | ||
.first; | ||
|
||
transformedFile = await fileAsset.readAsString(); | ||
expect( | ||
transformedFile.contains( | ||
'<script async type="application/dart" src="test.dart"></script>'), | ||
isFalse); | ||
expect( | ||
transformedFile.contains( | ||
'<script async src="packages/browser/dart.js"></script>'), | ||
isFalse); | ||
expect( | ||
transformedFile | ||
.contains('<script async="" src="test.dart.js"></script>'), | ||
isTrue); | ||
}); | ||
|
||
test('when run in debug mode', () async { | ||
configuration = new BarbackSettings(const {}, BarbackMode.DEBUG); | ||
transformer = new DartToJsScriptRewriter.asPlugin(configuration); | ||
AssetId fakeInputFileAssetId = | ||
new AssetId('testid', 'test/test_data/test_file.html'); | ||
|
||
MockAsset inputFile; | ||
MockTransform mockTransform; | ||
|
||
inputFile = new MockAsset(); | ||
mockTransform = new MockTransform(); | ||
|
||
when(inputFile.id).thenReturn(fakeInputFileAssetId); | ||
when(inputFile.readAsString()).thenReturn( | ||
new File.fromUri(Uri.parse('test/test_data/test_file.html')) | ||
.readAsString()); | ||
|
||
when(mockTransform.primaryInput).thenReturn(inputFile); | ||
when(mockTransform.readInputAsString(fakeInputFileAssetId)) | ||
.thenAnswer((_) { | ||
return new File.fromUri(Uri.parse('test/test_data/test_file.html')) | ||
.readAsString(); | ||
}); | ||
|
||
await transformer.apply(mockTransform); | ||
|
||
verifyNever(mockTransform.addOutput(any)); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
DartToJsScriptRewriter _transformer() { | ||
return new DartToJsScriptRewriter.asPlugin( | ||
new BarbackSettings({}, BarbackMode.RELEASE)); | ||
} | ||
|
||
final String _html = """ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script async type="application/dart" src="test.dart"></script> | ||
<script async src="packages/browser/dart.js"></script> | ||
</head> | ||
</html> | ||
"""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script async type="application/dart" src="test.dart"></script> | ||
<script async src="packages/browser/dart.js"></script> | ||
</head> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
library dart_to_js_script_rewriter.test.transformer_mocks; | ||
|
||
import 'package:barback/barback.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
class MockAsset extends Mock implements Asset {} | ||
|
||
class MockTransform extends Mock implements Transform {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
library tool.dev; | ||
|
||
import 'package:dart_dev/dart_dev.dart' show dev, config; | ||
|
||
main(List<String> args) async { | ||
List<String> directories = ['example/', 'lib/', 'test/', 'tool/']; | ||
|
||
config.analyze.entryPoints = directories; | ||
config.format.directories = directories; | ||
config.test | ||
..platforms = ['vm'] | ||
..pubServe = true | ||
..unitTests = ['test/']; | ||
|
||
config.coverage.pubServe = true; | ||
|
||
await dev(args); | ||
} |