-
Notifications
You must be signed in to change notification settings - Fork 229
Test package APIs rather than resource APIs. #1451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:path/path.dart' as p; | ||
import 'package:scheduled_test/scheduled_test.dart'; | ||
|
||
import '../../descriptor.dart' as d; | ||
import '../../test_pub.dart'; | ||
|
||
main() { | ||
integration('an immutable application sees a file: package config', () { | ||
servePackages((builder) { | ||
builder.serve("bar", "1.0.0"); | ||
|
||
builder.serve("foo", "1.0.0", | ||
deps: {"bar": "1.0.0"}, | ||
contents: [ | ||
d.dir("bin", [ | ||
d.file("script.dart", """ | ||
import 'dart:isolate'; | ||
|
||
main() async { | ||
print(await Isolate.packageRoot); | ||
print(await Isolate.packageConfig); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:foo/resource.txt'))); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:bar/resource.txt'))); | ||
} | ||
""") | ||
]) | ||
]); | ||
}); | ||
|
||
schedulePub(args: ["global", "activate", "foo"]); | ||
|
||
var pub = pubRun(global: true, args: ["foo:script"]); | ||
|
||
schedule(() async { | ||
pub.stdout.expect("null"); | ||
pub.stdout.expect(p.toUri( | ||
p.join(sandboxDir, cachePath, "global_packages/foo/.packages")) | ||
.toString()); | ||
pub.stdout.expect(p.toUri(p.join( | ||
sandboxDir, | ||
cachePath, | ||
"hosted/localhost%58${await globalPackageServer.port}/foo-1.0.0/" | ||
"lib/resource.txt")) | ||
.toString()); | ||
pub.stdout.expect(p.toUri(p.join( | ||
sandboxDir, | ||
cachePath, | ||
"hosted/localhost%58${await globalPackageServer.port}/bar-1.0.0/" | ||
"lib/resource.txt")) | ||
.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These three statements got wrapped an awful lot. It might be cleaner to declare little local variables for each path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
}); | ||
pub.shouldExit(0); | ||
}); | ||
|
||
integration('a mutable application sees an http: package root', () { | ||
d.dir("foo", [ | ||
d.libPubspec("foo", "1.0.0") | ||
]).create(); | ||
|
||
d.dir(appPath, [ | ||
d.appPubspec({"foo": {"path": "../foo"}}), | ||
d.dir("bin", [ | ||
d.file("script.dart", """ | ||
import 'dart:isolate'; | ||
|
||
main() async { | ||
print(await Isolate.packageRoot); | ||
print(await Isolate.packageConfig); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:myapp/resource.txt'))); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:foo/resource.txt'))); | ||
} | ||
""") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the same string as the above script, right? If so, declare a constant for it. Ideally stick it somewhere that the run/package_api_test can get to it too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I didn't share it across files, though, because I couldn't think of a nice semantic thing to call it. |
||
]) | ||
]).create(); | ||
|
||
schedulePub(args: ["global", "activate", "-s", "path", "."]); | ||
|
||
var pub = pubRun(global: true, args: ["myapp:script"]); | ||
|
||
pub.stdout.expect( | ||
allOf(startsWith("http://localhost:"), endsWith("/packages/"))); | ||
pub.stdout.expect("null"); | ||
pub.stdout.expect(allOf( | ||
startsWith("http://localhost:"), | ||
endsWith("/packages/myapp/resource.txt"))); | ||
pub.stdout.expect(allOf( | ||
startsWith("http://localhost:"), | ||
endsWith("/packages/foo/resource.txt"))); | ||
pub.shouldExit(0); | ||
}); | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:path/path.dart' as p; | ||
import 'package:scheduled_test/scheduled_test.dart'; | ||
|
||
import 'package:pub/src/io.dart'; | ||
|
||
import '../descriptor.dart' as d; | ||
import '../test_pub.dart'; | ||
|
||
const TRANSFORMER = """ | ||
import 'dart:async'; | ||
|
||
import 'package:barback/barback.dart'; | ||
|
||
class MyTransformer extends Transformer { | ||
MyTransformer.asPlugin(); | ||
|
||
String get allowedExtensions => '.in'; | ||
|
||
Future apply(Transform transform) async { | ||
transform.addOutput(new Asset.fromString( | ||
transform.primaryInput.id.changeExtension('.txt'), | ||
await transform.primaryInput.readAsString())); | ||
} | ||
} | ||
"""; | ||
|
||
main() { | ||
integration('an untransformed application sees a file: package config', () { | ||
d.dir("foo", [ | ||
d.libPubspec("foo", "1.0.0") | ||
]).create(); | ||
|
||
d.dir(appPath, [ | ||
d.appPubspec({"foo": {"path": "../foo"}}), | ||
d.dir("bin", [ | ||
d.file("script.dart", """ | ||
import 'dart:isolate'; | ||
|
||
main() async { | ||
print(await Isolate.packageRoot); | ||
print(await Isolate.packageConfig); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:myapp/resource.txt'))); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:foo/resource.txt'))); | ||
} | ||
""") | ||
]) | ||
]).create(); | ||
|
||
pubGet(); | ||
var pub = pubRun(args: ["bin/script"]); | ||
|
||
pub.stdout.expect("null"); | ||
pub.stdout.expect( | ||
p.toUri(p.join(sandboxDir, "myapp/.packages")).toString()); | ||
pub.stdout.expect( | ||
p.toUri(p.join(sandboxDir, "myapp/lib/resource.txt")).toString()); | ||
pub.stdout.expect( | ||
p.toUri(p.join(sandboxDir, "foo/lib/resource.txt")).toString()); | ||
pub.shouldExit(0); | ||
}); | ||
|
||
integration('a transformed application sees an http: package root', () { | ||
serveBarback(); | ||
|
||
d.dir("foo", [ | ||
d.libPubspec("foo", "1.0.0") | ||
]).create(); | ||
|
||
d.dir(appPath, [ | ||
d.pubspec({ | ||
"name": "myapp", | ||
"transformers": ["myapp/src/transformer"], | ||
"dependencies": {"barback": "any"} | ||
}), | ||
d.dir("lib", [ | ||
d.file("resource.in", "hello!"), | ||
d.dir("src", [ | ||
d.file("transformer.dart", TRANSFORMER) | ||
]) | ||
]), | ||
d.dir("bin", [ | ||
d.file("script.dart", """ | ||
import 'dart:isolate'; | ||
|
||
main() async { | ||
print(await Isolate.packageRoot); | ||
print(await Isolate.packageConfig); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:myapp/resource.txt'))); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:foo/resource.txt'))); | ||
} | ||
""") | ||
]) | ||
]).create(); | ||
|
||
pubGet(); | ||
var pub = pubRun(args: ["bin/script"]); | ||
|
||
pub.stdout.expect( | ||
allOf(startsWith("http://localhost:"), endsWith("/packages/"))); | ||
pub.stdout.expect("null"); | ||
pub.stdout.expect(allOf( | ||
startsWith("http://localhost:"), | ||
endsWith("/packages/myapp/resource.txt"))); | ||
pub.stdout.expect(allOf( | ||
startsWith("http://localhost:"), | ||
endsWith("/packages/foo/resource.txt"))); | ||
pub.shouldExit(0); | ||
}); | ||
|
||
integration('a snapshotted application sees a file: package root', () { | ||
servePackages((builder) { | ||
builder.serve("foo", "1.0.0", | ||
contents: [ | ||
d.dir("bin", [ | ||
d.file("script.dart", """ | ||
import 'dart:isolate'; | ||
|
||
main() async { | ||
print(await Isolate.packageRoot); | ||
print(await Isolate.packageConfig); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:myapp/resource.txt'))); | ||
print(await Isolate.resolvePackageUri( | ||
Uri.parse('package:foo/resource.txt'))); | ||
} | ||
""") | ||
]) | ||
]); | ||
}); | ||
|
||
d.dir(appPath, [ | ||
d.appPubspec({ | ||
"foo": "any" | ||
}) | ||
]).create(); | ||
|
||
pubGet(output: contains("Precompiled foo:script.")); | ||
|
||
var pub = pubRun(args: ["foo:script"]); | ||
|
||
pub.stdout.expect("null"); | ||
pub.stdout.expect( | ||
p.toUri(p.join(sandboxDir, "myapp/.packages")).toString()); | ||
pub.stdout.expect( | ||
p.toUri(p.join(sandboxDir, "myapp/lib/resource.txt")).toString()); | ||
schedule(() async { | ||
pub.stdout.expect(p.toUri(p.join( | ||
sandboxDir, | ||
cachePath, | ||
"hosted/localhost%58${await globalPackageServer.port}/foo-1.0.0/" | ||
"lib/resource.txt")) | ||
.toString()); | ||
}); | ||
pub.shouldExit(0); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2016
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.