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 withBarbackVersions("any", () { | 12 integration("loads different configurations from the same isolate", () { |
13 integration("loads different configurations from the same isolate", () { | 13 // If different configurations are loaded from different isolates, a |
14 // If different configurations are loaded from different isolates, a | 14 // transformer can end up being loaded twice. It's even possible for the |
15 // 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 |
16 // second load to use code that's transformed by the first, which is | 16 // really bad. This tests sets up such a scenario. |
17 // really bad. This tests sets up such a scenario. | 17 // |
18 // | 18 // The foo package has two self-transformers: foo/first and foo/second, |
19 // 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* |
20 // loaded in that order. This means that *no instances of foo/first* | 20 // should ever have their code transformed by foo/second. |
21 // should ever have their code transformed by foo/second. | 21 // |
22 // | 22 // The myapp package also has a reference to foo/first. This reference has |
23 // 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 |
24 // 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 |
25 // 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 |
26 // 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 |
27 // 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 |
28 // code than the previous instance. This tests asserts that that doesn't | 28 // happen. |
29 // happen. | |
30 | 29 |
31 d.dir("foo", [ | 30 d.dir("foo", [ |
32 d.pubspec({ | 31 d.pubspec({ |
33 "name": "foo", | 32 "name": "foo", |
34 "version": "1.0.0", | 33 "version": "1.0.0", |
35 "transformers": [ | 34 "transformers": [ |
36 {"foo/first": {"addition": " in foo"}}, | 35 {"foo/first": {"addition": " in foo"}}, |
37 "foo/second" | 36 "foo/second" |
38 ] | 37 ] |
39 }), | 38 }), |
40 d.dir("lib", [ | 39 d.dir("lib", [ |
41 d.file("first.dart", dartTransformer('foo/first')), | 40 d.file("first.dart", dartTransformer('foo/first')), |
42 d.file("second.dart", dartTransformer('foo/second')) | 41 d.file("second.dart", dartTransformer('foo/second')) |
43 ]) | 42 ]) |
44 ]).create(); | 43 ]).create(); |
45 | 44 |
46 d.dir(appPath, [ | 45 d.dir(appPath, [ |
47 d.pubspec({ | 46 d.pubspec({ |
48 "name": "myapp", | 47 "name": "myapp", |
49 "transformers": [ | 48 "transformers": [ |
50 { | 49 { |
51 "foo/first": { | 50 "foo/first": { |
52 "addition": " in myapp", | 51 "addition": " in myapp", |
53 "\$include": "web/first.dart" | 52 "\$include": "web/first.dart" |
54 } | 53 } |
55 }, | 54 }, |
56 {"foo/second": {"\$include": "web/second.dart"}} | 55 {"foo/second": {"\$include": "web/second.dart"}} |
57 ], | 56 ], |
58 "dependencies": {'foo': {'path': '../foo'}} | 57 "dependencies": {'foo': {'path': '../foo'}} |
59 }), | 58 }), |
60 d.dir("web", [ | 59 d.dir("web", [ |
61 // This is transformed by foo/first. It's used to see which | 60 // This is transformed by foo/first. It's used to see which |
62 // transformers ran on foo/first. | 61 // transformers ran on foo/first. |
63 d.file("first.dart", 'const TOKEN = "myapp/first";'), | 62 d.file("first.dart", 'const TOKEN = "myapp/first";'), |
64 | 63 |
65 // This is transformed by foo/second. It's used to see which | 64 // This is transformed by foo/second. It's used to see which |
66 // transformers ran on foo/second. | 65 // transformers ran on foo/second. |
67 d.file("second.dart", 'const TOKEN = "myapp/second";') | 66 d.file("second.dart", 'const TOKEN = "myapp/second";') |
68 ]) | 67 ]) |
69 ]).create(); | 68 ]).create(); |
70 | 69 |
71 createLockFile('myapp', sandbox: ['foo'], pkg: ['barback']); | 70 createLockFile('myapp', sandbox: ['foo'], pkg: ['barback']); |
72 | 71 |
73 pubServe(); | 72 pubServe(); |
74 | 73 |
75 // The version of foo/first used on myapp should have myapp's | 74 // The version of foo/first used on myapp should have myapp's |
76 // configuration and shouldn't be transformed by foo/second. | 75 // configuration and shouldn't be transformed by foo/second. |
77 requestShouldSucceed("first.dart", | 76 requestShouldSucceed("first.dart", |
78 'const TOKEN = "(myapp/first, foo/first in myapp)";'); | 77 'const TOKEN = "(myapp/first, foo/first in myapp)";'); |
79 | 78 |
80 // foo/second should be transformed by only foo/first. | 79 // foo/second should be transformed by only foo/first. |
81 requestShouldSucceed("second.dart", | 80 requestShouldSucceed("second.dart", |
82 'const TOKEN = "(myapp/second, (foo/second, foo/first in foo))";'); | 81 'const TOKEN = "(myapp/second, (foo/second, foo/first in foo))";'); |
83 | 82 |
84 endPubServe(); | 83 endPubServe(); |
85 }); | 84 }); |
86 }); | |
87 } | 85 } |
OLD | NEW |