| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library pub_tests; | 5 library pub_tests; |
| 6 | 6 |
| 7 import '../descriptor.dart' as d; | 7 import '../descriptor.dart' as d; |
| 8 import '../test_pub.dart'; | 8 import '../test_pub.dart'; |
| 9 import '../serve/utils.dart'; | 9 import '../serve/utils.dart'; |
| 10 | 10 |
| 11 main() { | 11 main() { |
| 12 integration("loads different configurations from the same isolate", () { | 12 integration("loads different configurations from the same isolate", () { |
| 13 // If different configurations are loaded from different isolates, a | 13 // If different configurations are loaded from different isolates, a |
| 14 // transformer can end up being loaded twice. It's even possible for the | 14 // transformer can end up being loaded twice. It's even possible for the |
| 15 // second load to use code that's transformed by the first, which is | 15 // second load to use code that's transformed by the first, which is |
| 16 // really bad. This tests sets up such a scenario. | 16 // really bad. This tests sets up such a scenario. |
| 17 // | 17 // |
| 18 // The foo package has two self-transformers: foo/first and foo/second, | 18 // The foo package has two self-transformers: foo/first and foo/second, |
| 19 // loaded in that order. This means that *no instances of foo/first* | 19 // loaded in that order. This means that *no instances of foo/first* |
| 20 // should ever have their code transformed by foo/second. | 20 // should ever have their code transformed by foo/second. |
| 21 // | 21 // |
| 22 // The myapp package also has a reference to foo/first. This reference has | 22 // The myapp package also has a reference to foo/first. This reference has |
| 23 // a different configuration than foo's, which means that if it's loaded | 23 // a different configuration than foo's, which means that if it's loaded |
| 24 // in a separate isolate, it will be loaded after all of foo's | 24 // in a separate isolate, it will be loaded after all of foo's |
| 25 // transformers have run. This means that foo/first.dart will have been | 25 // transformers have run. This means that foo/first.dart will have been |
| 26 // transformed by foo/first and foo/second, causing it to have different | 26 // transformed by foo/first and foo/second, causing it to have different |
| 27 // code than the previous instance. This tests asserts that that doesn't | 27 // code than the previous instance. This tests asserts that that doesn't |
| 28 // happen. | 28 // happen. |
| 29 | 29 |
| 30 serveBarback(); |
| 31 |
| 30 d.dir("foo", [ | 32 d.dir("foo", [ |
| 31 d.pubspec({ | 33 d.pubspec({ |
| 32 "name": "foo", | 34 "name": "foo", |
| 33 "version": "1.0.0", | 35 "version": "1.0.0", |
| 34 "transformers": [ | 36 "transformers": [ |
| 35 {"foo/first": {"addition": " in foo"}}, | 37 {"foo/first": {"addition": " in foo"}}, |
| 36 "foo/second" | 38 "foo/second" |
| 37 ] | 39 ], |
| 40 "dependencies": {"barback": "any"} |
| 38 }), | 41 }), |
| 39 d.dir("lib", [ | 42 d.dir("lib", [ |
| 40 d.file("first.dart", dartTransformer('foo/first')), | 43 d.file("first.dart", dartTransformer('foo/first')), |
| 41 d.file("second.dart", dartTransformer('foo/second')) | 44 d.file("second.dart", dartTransformer('foo/second')) |
| 42 ]) | 45 ]) |
| 43 ]).create(); | 46 ]).create(); |
| 44 | 47 |
| 45 d.dir(appPath, [ | 48 d.dir(appPath, [ |
| 46 d.pubspec({ | 49 d.pubspec({ |
| 47 "name": "myapp", | 50 "name": "myapp", |
| 48 "transformers": [ | 51 "transformers": [ |
| 49 { | 52 { |
| 50 "foo/first": { | 53 "foo/first": { |
| 51 "addition": " in myapp", | 54 "addition": " in myapp", |
| 52 "\$include": "web/first.dart" | 55 "\$include": "web/first.dart" |
| 53 } | 56 } |
| 54 }, | 57 }, |
| 55 {"foo/second": {"\$include": "web/second.dart"}} | 58 {"foo/second": {"\$include": "web/second.dart"}} |
| 56 ], | 59 ], |
| 57 "dependencies": {'foo': {'path': '../foo'}} | 60 "dependencies": { |
| 61 'foo': {'path': '../foo'}, |
| 62 'barback': 'any' |
| 63 } |
| 58 }), | 64 }), |
| 59 d.dir("web", [ | 65 d.dir("web", [ |
| 60 // This is transformed by foo/first. It's used to see which | 66 // This is transformed by foo/first. It's used to see which |
| 61 // transformers ran on foo/first. | 67 // transformers ran on foo/first. |
| 62 d.file("first.dart", 'const TOKEN = "myapp/first";'), | 68 d.file("first.dart", 'const TOKEN = "myapp/first";'), |
| 63 | 69 |
| 64 // This is transformed by foo/second. It's used to see which | 70 // This is transformed by foo/second. It's used to see which |
| 65 // transformers ran on foo/second. | 71 // transformers ran on foo/second. |
| 66 d.file("second.dart", 'const TOKEN = "myapp/second";') | 72 d.file("second.dart", 'const TOKEN = "myapp/second";') |
| 67 ]) | 73 ]) |
| 68 ]).create(); | 74 ]).create(); |
| 69 | 75 |
| 70 createLockFile('myapp', sandbox: ['foo'], pkg: ['barback']); | 76 pubGet(); |
| 71 | |
| 72 pubServe(); | 77 pubServe(); |
| 73 | 78 |
| 74 // The version of foo/first used on myapp should have myapp's | 79 // The version of foo/first used on myapp should have myapp's |
| 75 // configuration and shouldn't be transformed by foo/second. | 80 // configuration and shouldn't be transformed by foo/second. |
| 76 requestShouldSucceed("first.dart", | 81 requestShouldSucceed("first.dart", |
| 77 'const TOKEN = "(myapp/first, foo/first in myapp)";'); | 82 'const TOKEN = "(myapp/first, foo/first in myapp)";'); |
| 78 | 83 |
| 79 // foo/second should be transformed by only foo/first. | 84 // foo/second should be transformed by only foo/first. |
| 80 requestShouldSucceed("second.dart", | 85 requestShouldSucceed("second.dart", |
| 81 'const TOKEN = "(myapp/second, (foo/second, foo/first in foo))";'); | 86 'const TOKEN = "(myapp/second, (foo/second, foo/first in foo))";'); |
| 82 | 87 |
| 83 endPubServe(); | 88 endPubServe(); |
| 84 }); | 89 }); |
| 85 } | 90 } |
| OLD | NEW |