test_html_builder 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new51

test_html_builder #

A Dart builder that uses templates to generate HTML files for dart tests. Useful for projects with many tests that require custom HTML. Instead of having to replicate the custom HTML file for every test file that requires it, this builder can apply a template to any number of test files.

Usage #

Add this package as a dev_dependency:

dev_dependencies:
  test_html_builder: ^1.0.0

Create as many HTML test templates in the test/ directory as needed, e.g.:

<!-- test/example_template.html -->
<html>
    <head>
        <!-- Load custom assets needed by the test. -->
        <script src="custom.js"></script>

        <!-- Every template must include this token. -->
        {test}
        <!-- It will be replaced by the builder with the required tags:
        <link rel="x-dart-test" href="...">
        <script src="packages/test/dart.js"></script>
        -->
    </head>
</html>

Tell the builder which templates should be applied to which files, e.g.:

targets:
  $default:
    builders:
      test_html_builder:
        options:
          templates:
            "test/react_with_styles_template.html":
              - "test/components/styled/**_test.dart"
            "test/react_template.html":
              - "test/components/**_test.dart"

To illustrate how this works, consider an example test directory structure:

  • test/
    • foo_test.dart
    • react_template.html
    • react_with_styles_template.html
    • components/
      • bar_test.dart
      • styled/
        • baz_test.dart

Running tests via pub run build_runner test with the above configuration will result in the following (hidden) generated outputs:

  • test/components/bar_test.html (from react_template.html)
  • test/components/styled/baz_test.html (from react_with_styles_template.html)

Notes #

  • If there is overlap between the globs defined for multiple templates, the builder will choose the first template that matches.

  • If none of the templates match for a given test file, no html file will be generated.

  • One-off custom html files for individual tests are still supported, but they must use the .custom.html extension:

    • test/example_test.dart
    • test/example_test.custom.html

Contributing #

See the Contributing Guidelines.

1.0.2 #

  • Fix #8.

  • Address pub health/maintenance recommendations (add an example, add missing doc comments).

1.0.1 #

  • Update package metadata in pubspec.yaml.

1.0.0 #

  • Initial version.

example/README.md

Example #

The project/ directory contains an example project that consumes this test_html_builder. You should be able to run tests in this directory via pub run build_runner test and have them all pass.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  test_html_builder: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:test_html_builder/builder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
2
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
51
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Platform components identified in package: build, io.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
build ^1.1.4 1.2.0
build_config >=0.3.0 <0.5.0 0.4.1+1
glob ^1.1.7 1.2.0
json_annotation ^3.0.0 3.0.0
logging ^0.11.3+2 0.11.3+2
path ^1.6.4 1.6.4
Transitive dependencies
analyzer 0.38.5 0.39.0
args 1.5.2
async 2.4.0
charcode 1.1.2
checked_yaml 1.0.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
front_end 0.1.27 0.1.28
html 0.14.0+3
js 0.6.1+1
kernel 0.3.27 0.3.28
meta 1.1.7
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
pub_semver 1.4.2
pubspec_parse 0.1.5
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
build_runner ^1.3.0
build_test ^0.10.7+3
build_web_compilers ^2.3.0
dependency_validator ^1.2.0
pedantic ^1.8.0 1.8.0+1
test ^1.6.3