Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
c91b6571
Unverified
Commit
c91b6571
authored
Jun 07, 2019
by
Jonah Williams
Committed by
GitHub
Jun 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Codegen an entrypoint for flutter web applications (#33956)
parent
4e5cf5ef
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
321 additions
and
232 deletions
+321
-232
main.dart
dev/integration_tests/web/lib/main.dart
+1
-3
main_web.dart
examples/flutter_gallery/lib/main_web.dart
+0
-16
web_compilation_delegate.dart
..._tools/lib/src/build_runner/web_compilation_delegate.dart
+251
-17
build_web.dart
packages/flutter_tools/lib/src/commands/build_web.dart
+3
-29
context_runner.dart
packages/flutter_tools/lib/src/context_runner.dart
+0
-2
project.dart
packages/flutter_tools/lib/src/project.dart
+3
-0
asset_server.dart
packages/flutter_tools/lib/src/web/asset_server.dart
+4
-3
compile.dart
packages/flutter_tools/lib/src/web/compile.dart
+50
-67
web_device.dart
packages/flutter_tools/lib/src/web/web_device.dart
+9
-22
compile_test.dart
packages/flutter_tools/test/web/compile_test.dart
+0
-50
devices_test.dart
packages/flutter_tools/test/web/devices_test.dart
+0
-23
No files found.
dev/integration_tests/web/lib/main.dart
View file @
c91b6571
...
@@ -6,8 +6,6 @@ import 'package:flutter/widgets.dart';
...
@@ -6,8 +6,6 @@ import 'package:flutter/widgets.dart';
void
main
(
)
{
void
main
(
)
{
runApp
(
Center
(
runApp
(
Center
(
// Can remove when https://github.com/dart-lang/sdk/issues/35801 is fixed.
child:
const
Text
(
'Hello, World'
,
textDirection:
TextDirection
.
ltr
),
// ignore: prefer_const_constructors
child:
Text
(
'Hello, World'
,
textDirection:
TextDirection
.
ltr
),
));
));
}
}
examples/flutter_gallery/lib/main_web.dart
deleted
100644 → 0
View file @
4e5cf5ef
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Thanks for checking out Flutter!
// Like what you see? Tweet us @FlutterDev
import
'dart:ui'
as
ui
;
import
'package:flutter/material.dart'
;
import
'gallery/app.dart'
;
Future
<
void
>
main
()
async
{
await
ui
.
webOnlyInitializePlatform
();
// ignore: undefined_function
runApp
(
const
GalleryApp
());
}
packages/flutter_tools/lib/src/build_runner/web_compilation_delegate.dart
View file @
c91b6571
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/commands/build_web.dart
View file @
c91b6571
...
@@ -4,10 +4,8 @@
...
@@ -4,10 +4,8 @@
import
'dart:async'
;
import
'dart:async'
;
import
'../base/common.dart'
;
import
'../base/logger.dart'
;
import
'../build_info.dart'
;
import
'../build_info.dart'
;
import
'../
globals
.dart'
;
import
'../
project
.dart'
;
import
'../runner/flutter_command.dart'
import
'../runner/flutter_command.dart'
show
DevelopmentArtifact
,
FlutterCommandResult
;
show
DevelopmentArtifact
,
FlutterCommandResult
;
import
'../web/compile.dart'
;
import
'../web/compile.dart'
;
...
@@ -41,34 +39,10 @@ class BuildWebCommand extends BuildSubCommand {
...
@@ -41,34 +39,10 @@ class BuildWebCommand extends BuildSubCommand {
@override
@override
Future
<
FlutterCommandResult
>
runCommand
()
async
{
Future
<
FlutterCommandResult
>
runCommand
()
async
{
final
FlutterProject
flutterProject
=
FlutterProject
.
current
();
final
String
target
=
argResults
[
'target'
];
final
String
target
=
argResults
[
'target'
];
final
Status
status
=
logger
.
startProgress
(
'Compiling
$target
for the Web...'
,
timeout:
null
);
final
BuildInfo
buildInfo
=
getBuildInfo
();
final
BuildInfo
buildInfo
=
getBuildInfo
();
int
result
;
await
buildWeb
(
flutterProject
,
target
,
buildInfo
);
switch
(
buildInfo
.
mode
)
{
case
BuildMode
.
release
:
result
=
await
webCompiler
.
compileDart2js
(
target:
target
);
break
;
case
BuildMode
.
profile
:
result
=
await
webCompiler
.
compileDart2js
(
target:
target
,
minify:
false
);
break
;
case
BuildMode
.
debug
:
throwToolExit
(
'Debug mode is not supported as a build target. Instead use '
'"flutter run -d web".'
);
break
;
case
BuildMode
.
dynamicProfile
:
case
BuildMode
.
dynamicRelease
:
throwToolExit
(
'Build mode
${buildInfo.mode}
is not supported with JavaScript '
'compilation'
);
break
;
}
status
.
stop
();
if
(
result
==
1
)
{
throwToolExit
(
'Failed to compile
$target
to JavaScript.'
);
}
return
null
;
return
null
;
}
}
}
}
packages/flutter_tools/lib/src/context_runner.dart
View file @
c91b6571
...
@@ -44,7 +44,6 @@ import 'run_hot.dart';
...
@@ -44,7 +44,6 @@ import 'run_hot.dart';
import
'usage.dart'
;
import
'usage.dart'
;
import
'version.dart'
;
import
'version.dart'
;
import
'web/chrome.dart'
;
import
'web/chrome.dart'
;
import
'web/compile.dart'
;
import
'web/workflow.dart'
;
import
'web/workflow.dart'
;
import
'windows/visual_studio.dart'
;
import
'windows/visual_studio.dart'
;
import
'windows/visual_studio_validator.dart'
;
import
'windows/visual_studio_validator.dart'
;
...
@@ -104,7 +103,6 @@ Future<T> runInContext<T>(
...
@@ -104,7 +103,6 @@ Future<T> runInContext<T>(
UserMessages:
()
=>
UserMessages
(),
UserMessages:
()
=>
UserMessages
(),
VisualStudio:
()
=>
VisualStudio
(),
VisualStudio:
()
=>
VisualStudio
(),
VisualStudioValidator:
()
=>
const
VisualStudioValidator
(),
VisualStudioValidator:
()
=>
const
VisualStudioValidator
(),
WebCompiler:
()
=>
const
WebCompiler
(),
WebWorkflow:
()
=>
const
WebWorkflow
(),
WebWorkflow:
()
=>
const
WebWorkflow
(),
WindowsWorkflow:
()
=>
const
WindowsWorkflow
(),
WindowsWorkflow:
()
=>
const
WindowsWorkflow
(),
Xcode:
()
=>
Xcode
(),
Xcode:
()
=>
Xcode
(),
...
...
packages/flutter_tools/lib/src/project.dart
View file @
c91b6571
...
@@ -583,6 +583,9 @@ class WebProject {
...
@@ -583,6 +583,9 @@ class WebProject {
return
parent
.
directory
.
childDirectory
(
'web'
).
existsSync
();
return
parent
.
directory
.
childDirectory
(
'web'
).
existsSync
();
}
}
/// The html file used to host the flutter web application.
File
get
indexFile
=>
parent
.
directory
.
childDirectory
(
'web'
).
childFile
(
'index.html'
);
Future
<
void
>
ensureReadyForPlatformSpecificTooling
()
async
{
Future
<
void
>
ensureReadyForPlatformSpecificTooling
()
async
{
/// Generate index.html in build/web. Eventually we could support
/// Generate index.html in build/web. Eventually we could support
/// a custom html under the web sub directory.
/// a custom html under the web sub directory.
...
...
packages/flutter_tools/lib/src/web/asset_server.dart
View file @
c91b6571
...
@@ -66,6 +66,7 @@ class WebAssetServer {
...
@@ -66,6 +66,7 @@ class WebAssetServer {
/// An HTTP server which provides JavaScript and web assets to the browser.
/// An HTTP server which provides JavaScript and web assets to the browser.
Future
<
void
>
_onRequest
(
HttpRequest
request
)
async
{
Future
<
void
>
_onRequest
(
HttpRequest
request
)
async
{
final
String
targetName
=
'
${fs.path.basenameWithoutExtension(target)}
_web_entrypoint'
;
if
(
request
.
method
!=
'GET'
)
{
if
(
request
.
method
!=
'GET'
)
{
request
.
response
.
statusCode
=
HttpStatus
.
forbidden
;
request
.
response
.
statusCode
=
HttpStatus
.
forbidden
;
await
request
.
response
.
close
();
await
request
.
response
.
close
();
...
@@ -103,17 +104,17 @@ class WebAssetServer {
...
@@ -103,17 +104,17 @@ class WebAssetServer {
'flutter_web'
,
'flutter_web'
,
flutterProject
.
manifest
.
appName
,
flutterProject
.
manifest
.
appName
,
'lib'
,
'lib'
,
'
$
{fs.path.basename(target)}
.js'
,
'
$
targetName
.dart
.js'
,
));
));
await
_completeRequest
(
request
,
file
,
'text/javascript'
);
await
_completeRequest
(
request
,
file
,
'text/javascript'
);
}
else
if
(
uri
.
path
.
endsWith
(
'
$
{fs.path.basename(target)}
.bootstrap.js'
))
{
}
else
if
(
uri
.
path
.
endsWith
(
'
$
targetName
.dart
.bootstrap.js'
))
{
final
File
file
=
fs
.
file
(
fs
.
path
.
join
(
final
File
file
=
fs
.
file
(
fs
.
path
.
join
(
flutterProject
.
dartTool
.
path
,
flutterProject
.
dartTool
.
path
,
'build'
,
'build'
,
'flutter_web'
,
'flutter_web'
,
flutterProject
.
manifest
.
appName
,
flutterProject
.
manifest
.
appName
,
'lib'
,
'lib'
,
'
$
{fs.path.basename(target)}
.bootstrap.js'
,
'
$
targetName
.dart
.bootstrap.js'
,
));
));
await
_completeRequest
(
request
,
file
,
'text/javascript'
);
await
_completeRequest
(
request
,
file
,
'text/javascript'
);
}
else
if
(
uri
.
path
.
contains
(
'dart_sdk'
))
{
}
else
if
(
uri
.
path
.
contains
(
'dart_sdk'
))
{
...
...
packages/flutter_tools/lib/src/web/compile.dart
View file @
c91b6571
...
@@ -4,80 +4,56 @@
...
@@ -4,80 +4,56 @@
import
'package:meta/meta.dart'
;
import
'package:meta/meta.dart'
;
import
'../a
rtifacts
.dart'
;
import
'../a
sset
.dart'
;
import
'../base/common.dart'
;
import
'../base/common.dart'
;
import
'../base/context.dart'
;
import
'../base/context.dart'
;
import
'../base/file_system.dart'
;
import
'../base/file_system.dart'
;
import
'../base/io.dart'
;
import
'../base/logger.dart'
;
import
'../base/process_manager.dart'
;
import
'../build_info.dart'
;
import
'../build_info.dart'
;
import
'../
convert
.dart'
;
import
'../
bundle
.dart'
;
import
'../globals.dart'
;
import
'../globals.dart'
;
import
'../project.dart'
;
/// The [WebCompiler] instance.
WebCompiler
get
webCompiler
=>
context
.
get
<
WebCompiler
>();
/// The [WebCompilationProxy] instance.
/// The [WebCompilationProxy] instance.
WebCompilationProxy
get
webCompilationProxy
=>
WebCompilationProxy
get
webCompilationProxy
=>
context
.
get
<
WebCompilationProxy
>();
context
.
get
<
WebCompilationProxy
>();
/// A wrapper around dart tools for web compilation.
class
WebCompiler
{
const
WebCompiler
();
/// Compile `target` using dart2js.
Future
<
void
>
buildWeb
(
FlutterProject
flutterProject
,
String
target
,
BuildInfo
buildInfo
)
async
{
///
final
Status
status
=
logger
.
startProgress
(
'Compiling
$target
for the Web...'
,
timeout:
null
);
/// `minify` controls whether minifaction of the source is enabled. Defaults to `true`.
final
Directory
outputDir
=
fs
.
directory
(
getWebBuildDirectory
())
/// `enabledAssertions` controls whether assertions are enabled. Defaults to `false`.
..
createSync
(
recursive:
true
);
Future
<
int
>
compileDart2js
({
bool
result
;
@required
String
target
,
try
{
bool
minify
=
true
,
result
=
await
webCompilationProxy
.
initialize
(
bool
enabledAssertions
=
false
,
projectDirectory:
FlutterProject
.
current
().
directory
,
})
async
{
targets:
<
String
>[
target
],
final
String
engineDartPath
=
release:
buildInfo
.
isRelease
,
artifacts
.
getArtifactPath
(
Artifact
.
engineDartBinary
);
);
final
String
dart2jsPath
=
if
(
result
)
{
artifacts
.
getArtifactPath
(
Artifact
.
dart2jsSnapshot
);
// Places assets adjacent to the web stuff.
final
String
flutterWebSdkPath
=
final
AssetBundle
assetBundle
=
AssetBundleFactory
.
instance
.
createBundle
();
artifacts
.
getArtifactPath
(
Artifact
.
flutterWebSdk
);
await
assetBundle
.
build
();
final
String
librariesPath
=
await
writeBundle
(
fs
.
directory
(
fs
.
path
.
join
(
outputDir
.
path
,
'assets'
)),
assetBundle
.
entries
);
fs
.
path
.
join
(
flutterWebSdkPath
,
'libraries.json'
);
final
Directory
outputDir
=
fs
.
directory
(
getWebBuildDirectory
());
if
(!
outputDir
.
existsSync
())
{
outputDir
.
createSync
(
recursive:
true
);
}
final
String
outputPath
=
fs
.
path
.
join
(
outputDir
.
path
,
'main.dart.js'
);
if
(!
processManager
.
canRun
(
engineDartPath
))
{
throwToolExit
(
'Unable to find Dart binary at
$engineDartPath
'
);
}
/// Compile Dart to JavaScript.
// Copy results to output directory.
final
List
<
String
>
command
=
<
String
>[
final
String
outputPath
=
fs
.
path
.
join
(
engineDartPath
,
flutterProject
.
dartTool
.
path
,
dart2jsPath
,
'build'
,
target
,
'flutter_web'
,
'-o'
,
flutterProject
.
manifest
.
appName
,
'
$outputPath
'
,
'
${fs.path.withoutExtension(target)}
_web_entrypoint.dart.js'
'-O4'
,
);
'--libraries-spec=
$librariesPath
'
,
fs
.
file
(
outputPath
).
copySync
(
fs
.
path
.
join
(
outputDir
.
path
,
'main.dart.js'
));
];
fs
.
file
(
'
$outputPath
.map'
).
copySync
(
fs
.
path
.
join
(
outputDir
.
path
,
'main.dart.js.map'
));
if
(
minify
)
{
flutterProject
.
web
.
indexFile
.
copySync
(
fs
.
path
.
join
(
outputDir
.
path
,
'index.html'
));
command
.
add
(
'-m'
);
}
}
if
(
enabledAssertions
)
{
}
catch
(
err
)
{
command
.
add
(
'--enable-asserts'
);
printError
(
err
.
toString
());
}
result
=
false
;
printTrace
(
command
.
join
(
' '
));
}
finally
{
final
Process
result
=
await
processManager
.
start
(
command
);
status
.
stop
();
result
.
stdout
}
.
transform
(
utf8
.
decoder
)
if
(
result
==
false
)
{
.
transform
(
const
LineSplitter
())
throwToolExit
(
'Failed to compile
$target
for the Web.'
);
.
listen
(
printStatus
);
result
.
stderr
.
transform
(
utf8
.
decoder
)
.
transform
(
const
LineSplitter
())
.
listen
(
printError
);
return
result
.
exitCode
;
}
}
}
}
...
@@ -87,12 +63,19 @@ class WebCompiler {
...
@@ -87,12 +63,19 @@ class WebCompiler {
class
WebCompilationProxy
{
class
WebCompilationProxy
{
const
WebCompilationProxy
();
const
WebCompilationProxy
();
/// Initialize the web compiler output to `outputDirectory` from a project spawned at
/// Initialize the web compiler from the `projectDirectory`.
/// `projectDirectory`.
///
Future
<
void
>
initialize
({
/// Returns whether or not the build was successful.
///
/// `release` controls whether we build the bundle for dartdevc or only
/// the entrypoints for dart2js to later take over.
///
/// `targets` controls the specific compiler targets.
Future
<
bool
>
initialize
({
@required
Directory
projectDirectory
,
@required
Directory
projectDirectory
,
@required
List
<
String
>
targets
,
@required
List
<
String
>
targets
,
String
testOutputDir
,
String
testOutputDir
,
bool
release
,
})
async
{
})
async
{
throw
UnimplementedError
();
throw
UnimplementedError
();
}
}
...
...
packages/flutter_tools/lib/src/web/web_device.dart
View file @
c91b6571
...
@@ -5,15 +5,11 @@
...
@@ -5,15 +5,11 @@
import
'package:meta/meta.dart'
;
import
'package:meta/meta.dart'
;
import
'../application_package.dart'
;
import
'../application_package.dart'
;
import
'../asset.dart'
;
import
'../base/common.dart'
;
import
'../base/file_system.dart'
;
import
'../base/file_system.dart'
;
import
'../base/io.dart'
;
import
'../base/io.dart'
;
import
'../base/logger.dart'
;
import
'../base/platform.dart'
;
import
'../base/platform.dart'
;
import
'../base/process_manager.dart'
;
import
'../base/process_manager.dart'
;
import
'../build_info.dart'
;
import
'../build_info.dart'
;
import
'../bundle.dart'
;
import
'../device.dart'
;
import
'../device.dart'
;
import
'../globals.dart'
;
import
'../globals.dart'
;
import
'../project.dart'
;
import
'../project.dart'
;
...
@@ -22,15 +18,15 @@ import '../web/workflow.dart';
...
@@ -22,15 +18,15 @@ import '../web/workflow.dart';
import
'chrome.dart'
;
import
'chrome.dart'
;
class
WebApplicationPackage
extends
ApplicationPackage
{
class
WebApplicationPackage
extends
ApplicationPackage
{
WebApplicationPackage
(
this
.
_flutterProject
)
:
super
(
id:
_
flutterProject
.
manifest
.
appName
);
WebApplicationPackage
(
this
.
flutterProject
)
:
super
(
id:
flutterProject
.
manifest
.
appName
);
final
FlutterProject
_
flutterProject
;
final
FlutterProject
flutterProject
;
@override
@override
String
get
name
=>
_
flutterProject
.
manifest
.
appName
;
String
get
name
=>
flutterProject
.
manifest
.
appName
;
/// The location of the web source assets.
/// The location of the web source assets.
Directory
get
webSourcePath
=>
_
flutterProject
.
directory
.
childDirectory
(
'web'
);
Directory
get
webSourcePath
=>
flutterProject
.
directory
.
childDirectory
(
'web'
);
}
}
class
WebDevice
extends
Device
{
class
WebDevice
extends
Device
{
...
@@ -121,20 +117,11 @@ class WebDevice extends Device {
...
@@ -121,20 +117,11 @@ class WebDevice extends Device {
bool
usesTerminalUi
=
true
,
bool
usesTerminalUi
=
true
,
bool
ipv6
=
false
,
bool
ipv6
=
false
,
})
async
{
})
async
{
final
Status
status
=
logger
.
startProgress
(
'Compiling
${package.name}
to JavaScript...'
,
timeout:
null
);
await
buildWeb
(
final
int
result
=
await
webCompiler
.
compileDart2js
(
target:
mainPath
,
minify:
false
,
enabledAssertions:
true
);
package
.
flutterProject
,
status
.
stop
();
fs
.
path
.
relative
(
mainPath
,
from:
package
.
flutterProject
.
directory
.
path
),
if
(
result
!=
0
)
{
debuggingOptions
.
buildInfo
,
printError
(
'Failed to compile
${package.name}
to JavaScript'
);
);
return
LaunchResult
.
failed
();
}
final
AssetBundle
assetBundle
=
AssetBundleFactory
.
instance
.
createBundle
();
final
int
build
=
await
assetBundle
.
build
();
if
(
build
!=
0
)
{
throwToolExit
(
'Error: Failed to build asset bundle'
);
}
await
writeBundle
(
fs
.
directory
(
getAssetBuildDirectory
()),
assetBundle
.
entries
);
_package
=
package
;
_package
=
package
;
_server
=
await
HttpServer
.
bind
(
InternetAddress
.
loopbackIPv4
,
0
);
_server
=
await
HttpServer
.
bind
(
InternetAddress
.
loopbackIPv4
,
0
);
_server
.
listen
(
_basicAssetServer
);
_server
.
listen
(
_basicAssetServer
);
...
...
packages/flutter_tools/test/web/compile_test.dart
deleted
100644 → 0
View file @
4e5cf5ef
// Copyright 2019 The Chromium Authors. 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:flutter_tools/src/artifacts.dart'
;
import
'package:flutter_tools/src/globals.dart'
;
import
'package:flutter_tools/src/web/compile.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'../src/common.dart'
;
import
'../src/mocks.dart'
;
import
'../src/testbed.dart'
;
void
main
(
)
{
group
(
WebCompiler
,
()
{
MockProcessManager
mockProcessManager
;
Testbed
testBed
;
setUp
(()
{
mockProcessManager
=
MockProcessManager
();
testBed
=
Testbed
(
setup:
()
async
{
final
String
engineDartPath
=
artifacts
.
getArtifactPath
(
Artifact
.
engineDartBinary
);
when
(
mockProcessManager
.
start
(
any
)).
thenAnswer
((
Invocation
invocation
)
async
=>
FakeProcess
());
when
(
mockProcessManager
.
canRun
(
engineDartPath
)).
thenReturn
(
true
);
},
overrides:
<
Type
,
Generator
>{
ProcessManager:
()
=>
mockProcessManager
,
});
});
test
(
'invokes dart2js with correct arguments'
,
()
=>
testBed
.
run
(()
async
{
await
webCompiler
.
compileDart2js
(
target:
'lib/main.dart'
);
verify
(
mockProcessManager
.
start
(<
String
>[
'bin/cache/dart-sdk/bin/dart'
,
'bin/cache/dart-sdk/bin/snapshots/dart2js.dart.snapshot'
,
'lib/main.dart'
,
'-o'
,
'build/web/main.dart.js'
,
'-O4'
,
'--libraries-spec=bin/cache/flutter_web_sdk/libraries.json'
,
'-m'
,
])).
called
(
1
);
}));
});
}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
packages/flutter_tools/test/web/devices_test.dart
View file @
c91b6571
...
@@ -2,12 +2,9 @@
...
@@ -2,12 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/web/chrome.dart'
;
import
'package:flutter_tools/src/web/chrome.dart'
;
import
'package:flutter_tools/src/web/compile.dart'
;
import
'package:flutter_tools/src/web/web_device.dart'
;
import
'package:flutter_tools/src/web/web_device.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'package:process/process.dart'
;
...
@@ -17,37 +14,18 @@ import '../src/context.dart';
...
@@ -17,37 +14,18 @@ import '../src/context.dart';
void
main
(
)
{
void
main
(
)
{
group
(
WebDevice
,
()
{
group
(
WebDevice
,
()
{
MockWebCompiler
mockWebCompiler
;
MockChromeLauncher
mockChromeLauncher
;
MockChromeLauncher
mockChromeLauncher
;
MockPlatform
mockPlatform
;
MockPlatform
mockPlatform
;
FlutterProject
flutterProject
;
MockProcessManager
mockProcessManager
;
MockProcessManager
mockProcessManager
;
setUp
(()
async
{
setUp
(()
async
{
mockProcessManager
=
MockProcessManager
();
mockProcessManager
=
MockProcessManager
();
mockChromeLauncher
=
MockChromeLauncher
();
mockChromeLauncher
=
MockChromeLauncher
();
mockPlatform
=
MockPlatform
();
mockPlatform
=
MockPlatform
();
mockWebCompiler
=
MockWebCompiler
();
flutterProject
=
FlutterProject
.
fromPath
(
fs
.
path
.
join
(
getFlutterRoot
(),
'dev'
,
'integration_tests'
,
'web'
));
when
(
mockWebCompiler
.
compileDart2js
(
target:
anyNamed
(
'target'
),
minify:
anyNamed
(
'minify'
),
enabledAssertions:
anyNamed
(
'enabledAssertions'
),
)).
thenAnswer
((
Invocation
invocation
)
async
=>
0
);
when
(
mockChromeLauncher
.
launch
(
any
)).
thenAnswer
((
Invocation
invocation
)
async
{
when
(
mockChromeLauncher
.
launch
(
any
)).
thenAnswer
((
Invocation
invocation
)
async
{
return
null
;
return
null
;
});
});
});
});
testUsingContext
(
'can build and connect to chrome'
,
()
async
{
final
WebDevice
device
=
WebDevice
();
await
device
.
startApp
(
WebApplicationPackage
(
flutterProject
));
},
overrides:
<
Type
,
Generator
>{
ChromeLauncher:
()
=>
mockChromeLauncher
,
WebCompiler:
()
=>
mockWebCompiler
,
Platform:
()
=>
mockPlatform
,
});
testUsingContext
(
'Invokes version command on non-Windows platforms'
,
()
async
{
testUsingContext
(
'Invokes version command on non-Windows platforms'
,
()
async
{
when
(
mockPlatform
.
isWindows
).
thenReturn
(
false
);
when
(
mockPlatform
.
isWindows
).
thenReturn
(
false
);
when
(
mockPlatform
.
environment
).
thenReturn
(<
String
,
String
>{
when
(
mockPlatform
.
environment
).
thenReturn
(<
String
,
String
>{
...
@@ -86,7 +64,6 @@ void main() {
...
@@ -86,7 +64,6 @@ void main() {
}
}
class
MockChromeLauncher
extends
Mock
implements
ChromeLauncher
{}
class
MockChromeLauncher
extends
Mock
implements
ChromeLauncher
{}
class
MockWebCompiler
extends
Mock
implements
WebCompiler
{}
class
MockPlatform
extends
Mock
implements
Platform
{}
class
MockPlatform
extends
Mock
implements
Platform
{}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
class
MockProcessResult
extends
Mock
implements
ProcessResult
{
class
MockProcessResult
extends
Mock
implements
ProcessResult
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment