| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:io'; |
| 6 import 'dart:convert'; |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:path/path.dart' as path; |
| 10 import 'package:expect/expect.dart'; |
| 11 import 'package:source_maps/source_maps.dart'; |
| 12 |
| 13 checkConsistency(Uri outUri) { |
| 14 print('Accessing $outUri'); |
| 15 File sourceFile = new File.fromUri(outUri); |
| 16 Expect.isTrue(sourceFile.existsSync()); |
| 17 String mapName = getMapReferenceFromJsOutput(sourceFile.readAsStringSync()); |
| 18 Uri mapUri = outUri.resolve(mapName); |
| 19 print('Accessing $mapUri'); |
| 20 File mapFile = new File.fromUri(mapUri); |
| 21 Expect.isTrue(mapFile.existsSync()); |
| 22 SingleMapping sourceMap = new SingleMapping.fromJson( |
| 23 JSON.decode(mapFile.readAsStringSync())); |
| 24 Expect.equals(outUri, mapUri.resolve(sourceMap.targetUrl)); |
| 25 } |
| 26 |
| 27 String getMapReferenceFromJsOutput(String file) { |
| 28 List<String> out = file.split('\n'); |
| 29 String mapReference = out[out.length - 3]; // #sourceMappingURL=<url> |
| 30 Expect.isTrue(mapReference.startsWith('//# sourceMappingURL=')); |
| 31 return mapReference.substring(mapReference.indexOf('=') + 1); |
| 32 } |
| 33 |
| 34 copyDirectory(Directory sourceDir, Directory destinationDir) { |
| 35 sourceDir.listSync().forEach((FileSystemEntity element) { |
| 36 String newPath = path.join(destinationDir.path, |
| 37 path.basename(element.path)); |
| 38 if (element is File) { |
| 39 element.copySync(newPath); |
| 40 } else if (element is Directory) { |
| 41 Directory newDestinationDir = new Directory(newPath); |
| 42 newDestinationDir.createSync(); |
| 43 copyDirectory(element, newDestinationDir); |
| 44 } |
| 45 }); |
| 46 } |
| 47 |
| 48 Future<Directory> createTempDir() { |
| 49 return Directory.systemTemp |
| 50 .createTemp('sourceMap_test-') |
| 51 .then((Directory dir) { |
| 52 return dir; |
| 53 }); |
| 54 } |
| OLD | NEW |