Dart Test client- side HTML configuration - dart

I understand that the package:unittest/unittest.dart is deprecated and the new package is package:test/test.dart.
Which are the equivalent of the library package:unittest/html_config.dart and the useHtmlConfiguration() function in the new test.dart framework.
Thanks.
Note: I am reading an outdated book ("Dart in Action"). So far I have been able to match the deprecated parts with the new standard parts of Dart.
Except now that I am reading the section of Unit-Test.
source code
.
├── PackList.dart
├── PackList.html
├── pubspec.lock
├── pubspec.yaml
├── styles.css
└── test
├── PackList_test.dart
└── PackList_test.html
I am trying to check if the value that the constructor return is not NULL.
import "package:test/test.dart";
import "../PackList.dart" as packListApp;
main() {
test("PackItem constructor", () {
var item = new packListApp.PackItem("Towel");
expect(item, isNotNull);
});
}
The source code works.
This is just an excersice to understand how the test framework works.
I expect item to be a new object.
With this properties initialized after var item = new packListApp.PackItem("Towel");
print(packItem.uiElement); //Towel
print(packItem.itemText); //div
The problem is that I don't know how do related the html part of my source code with the test.
When I run this test, I got this errors.
pub run test
00:00 +0 -1: loading test/PackList_test.dart [E]
Failed to load "test/PackList_test.dart":
Unable to spawn isolate: The built-in library 'dart:html' is not available on the stand-alone VM.
PackList.dart: line 1 pos 1: library handler failed
import "dart:html";
^
00:00 +0 -1: Some tests failed.
If I add #TestOn("dartium"), I got this message.
pub run test
No tests ran.

pub run test just runs VM tests. If you want to run browser tests, you need to explicitly tell it like
pub run test -pdartium
The my_test.html needs to contain
<link rel="x-dart-test" href="my_test.dart">
instead of a normal Dart script tag

Related

What is the Difference between Dart console-full and console-simple application?

While learning dart I came across to these type of console application, so I just want to know What is the Difference between Dart console-full and console-simple application?
Both templates generate a Dart project with some default files:
.dart_tool/package_config.json
.gitignore
.packages
analysis_options.yaml
CHANGELOG.md
pubspec.lock
pubspec.yaml
README.md
But does then also create Dart files which depends on the type of template:
console-simple
Creates a very basic Dart project with a single Dart file named bin/<project_name>.dart with the content:
void main(List<String> arguments) {
print('Hello world!');
}
console-full
Create a more complete Dart project where we split the code into bin/, lib/, and test/. The description in the auto-generated README.md file does explain the file structure:
A sample command-line application with an entrypoint in bin/, library code
in lib/, and example unit test in test/.
The project makes use of the test package for unit testing so the project will by default include this package in the pubspec.yaml.
Following Dart files is generated to make use of the three directories:
// bin/project_name.dart
import 'package:project_name/project_name.dart' as project_name;
void main(List<String> arguments) {
print('Hello world: ${project_name.calculate()}!');
}
// lib/project_name.dart
int calculate() {
return 6 * 7;
}
// test/project_name_test.dart
import 'package:project_name/project_name.dart';
import 'package:test/test.dart';
void main() {
test('calculate', () {
expect(calculate(), 42);
});
}

Local references in imported Terraform module

I have TF modules on bitbucket in the terraform-modules project.
In my main module (in the azure/main_module directory) on bitbucket I have:
azure
|
+- sub_module
main.tf
main_module
main.tf
In main_module/main.tf I have the following file structure:
azure
|
+-general
|
+-main.tf
module "my_sub_module" {
source = "../azure/sub_module/"
...
}
Now, in another project, in another module I have:
module "credit" {
source = "git::bitbucket.org:myorg/terraform-modules.git//main_module"
...
}
I get the following error when running tf plan in the other project:
Error: Unreadable module directory
Unable to evaluate directory symlink: lstat
.terraform/modules/main_module/azure/azure: no such file or directory
Everything works when the local references are replaced with bitbucket references.
So it seems as though the main_module is imported, but then the local references in that project is are interpreted as local references in the importing project (the one with the general module) and then it can't find additional modules because it is searching in the wrong project?
Any ideas how this can be fixed, while still using local references in the imported project?

How to import generated source in dart2 using build_runner?

I want to create a Builder that would create Env class on the fly. That class should be available for import anywhere in my project. It is as container for environment constants defined in build.yml
Builder itself works fine, it generates desired output, however when I run
pub run build_runner build
build fails with following message
[SEVERE] build_web_compilers:entrypoint on web/main.dart: Unable to
find modules for some sources, this is usually the result of either a
bad import, a missing dependency in a package (or possibly a
dev_dependency needs to move to a real dependency), or a build failure
(if importing a generated file).
Please check the following imports:
import
'../.dart_tool/build/generated/buildertest/lib/environment.g.dart';
from buildertest|web/main.dart at 2:1
[INFO] Running build completed, took 4.1s [INFO] Caching finalized
dependency graph completed, took 450ms [SEVERE] Failed after 4.6s
import by itself is ok, as it works fine when I run following snippet
import '../.dart_tool/build/generated/buildertest/lib/environment.g.dart';
void main() {
print("Name:${Environment.name}");
print("Endpoint:${Environment.endpoint}");
}
with
dart web/main.dart
What should be done to make this import valid??
Here is build.yaml
targets:
$default:
builders:
angular_components|scss_builder:
enabled: True
env|builder:
options:
name: "default"
endpoint: "http://example.org"
enabled: true
builders:
env|builder:
import: "env/EnvBuilder.dart"
builder_factories: ["builderFactory"]
is_optional: false
build_extensions:
"$lib$": ["environment.g.dart"]
auto_apply: root_package
runs_before: ["build_test:test_bootstrap","build_modules:module_library","build_modules:dartdevc","build_web_compilers:ddc","build_modules:vm","build_modules:dart2js","build_web_compilers:entrypoint"]

What does the "#" symbol mean in Bazel?

I'm studying Bazel building system at present. I always see the # symbol in Bazel script, but I cannot find any documentation about it. I searched it on the website of Bazel but the result seems useless.
# in Bazel.
For example:
filegroup(
name = "toolchain_fg",
srcs = [
":cc-compiler-amd64",
"#x86_64_unknown_linux_gnu_gcc_730//:compiler_components",
],
)
Could anybody explain the # symbol here for me?
This is to reference a remote repository.
From the doc, depending on other Bazel projects
local_repository(
name = "coworkers_project",
path = "/path/to/coworkers-project",
)
If your coworker has a target //foo:bar, your project can refer to it
as #coworkers_project//foo:bar.
See also the design doc of remote repository and bind example in workspace rules.
In Bazel, targets are referred by labels.
Bazel labels have the following format:
#repoName//packageName:target
For example, in the following packages found in myRepo:
myRepo
├── WORKSPACE
├── package1
│ └── BUILD
│ └── src
└── package2
├── BUILD
└── src
a target called myTarget in package1/BUILD can be labeled as as #myRepo//package1:myTarget globally.
If referenced from the same repo, for example from package2/BUILD, then the #myRepo prefix can be omitted and you can use //package1:myTarget.
If referenced from the same package, for example in another target from package1/BUILD, then the package name can be omitted and you can use :myTarget. The colon can also be omitted if it does not create confusion with a name. Such short form labels should not be confused with the names. Labels start with '//' or ':'. But names never do. For example, the name of the first package is package1 but its label is //package1.
Reference: https://docs.bazel.build/versions/master/build-ref.html

swift build use of unresolved identifier

I used vapor to build a project. create a swift file using xcode.
structure like this:
├── Sources
│ └──App
│ │ └── Controllers
│ │ └── Models
│ │ │ └── File.swift
│ └──Run
│ └── main.swift
└── Package.swift
with main.swift
let config = try Config()
try config.setup()
let drop = try Droplet(config)
try drop.setup()
File.test()
try drop.run()
with File.swift
class File {
class func test() -> Void{
print("--\(self)--");
}
}
the above code xcode can run normally. but using the command swift build to get an error.
log:
Compile Swift Module 'App' (6 sources)
Compile Swift Module 'Run' (1 sources)
/Users/xxx/Documents/testServer/Sources/Run/main.swift:25:1: error: use of
unresolved identifier 'File'
File.test()
^~~~
CoreServices.cFile:1:12: note: did you mean 'cFile'?
public var cFile: OSType { get }
^
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/xxx/Documents/testServer/.build/debug.yamlhere
Your main.swift is in module Run, while File is in module App. To call a method of a class from another module, you have to perform the following:
Make the class (File) public
Make the method (test) public
Import the module in the file of the calling method - add import App to main.swift
Probably what is happening is that your class File is in the target 'App', while your Main is in target 'Run', so one can't see the other.
What you need to do is to add the line File.test() into Droplet+setup.swift file over setup() function, that you might have in your project located over the 'App' target.
Some thing like this:
#_exported import Vapor
extension Droplet {
public func setup() throws {
try setupRoutes()
// ADD YOUR CLASS CALL OVER HERE
File.test()
}
}

Resources