goldenrod 0.1.0

  • Readme
  • Changelog
  • Installing
  • new51

Goldenrod #

Goldenrod is a simple set of matchers that enables simple golden-file based String assertions for Dart and Flutter testing.

Binary on pub.dev Code coverage Github action status Dartdocs Style guide

Ever tired of writing tests like?

import 'package:app/app.dart';
import 'package:test/test.dart';

void main() {
  test('should output a pretty string', () {
    expect(shrugEmoji(), '¯\_(ツ)_/¯');
  });
}

... and needing to manually update the assertions when you update your app? Automate it using golden-file based matches and package:goldenrod!

NOTE: This package assumes access to File I/O using dart:io, and will not work properly (or at all) in read-only file systems, or in environments where dart:io is not available (such as on the web).

Add @TestOn('vm') to the top of your tests that use package:goldenrod!

@TestOn('vm')
import 'package:app/app.dart';
import 'package:goldenrod/goldenrod.dart';
import 'package:test/test.dart';

void main() {
  test('should output a pretty string', () async {
    expect(shrugEmoji(), await matchesGoldenText(file: 'test/shrug.golden'));
  });
}

To update goldens pass the environment variable GOLDENROD_UPDATE=true:

GOLDENROD_UPDATE=true pub run test

matchesGoldenText #

Asserts that the actual String matches the contents of the file specified:

// test/foo_test.dart
@TestOn('vm')
import 'package:app/app.dart';
import 'package:goldenrod/goldenrod.dart';
import 'package:test/test.dart';

void main() {
  test('some computation is stable', () async {
    expect(fooString(), await matchesGoldenText(file: 'test/foo_test.golden'));
  });
}

matchesGoldenKey #

Asserts than the actual String matches the value of the JSON file/key:

// test/foo_test.dart
@TestOn('vm')
import 'package:app/app.dart';
import 'package:goldenrod/goldenrod.dart';
import 'package:test/test.dart';

void main() {
  test('some computation is stable', () async {
    expect(a(), await matchesGoldenKey(file: 'test/foo_test.golden', key: 'a'));
    expect(b(), await matchesGoldenKey(file: 'test/foo_test.golden', key: 'b'));
  });
}

CHANGELOG #

0.1.0 #

Initial commit.

Use this package as a library

1. Depend on it

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


dependencies:
  goldenrod: ^0.1.0

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:goldenrod/goldenrod.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
1
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 Jul 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because of the import of dart:io via the import chain package:goldenrod/goldenrod.dartdart:io

Package not compatible with runtime web

Because of the import of dart:io via the import chain package:goldenrod/goldenrod.dartdart:io

Maintenance suggestions

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and goldenrod.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.8.0 <3.0.0
matcher ^0.12.8 0.12.8
meta ^1.1.8 1.2.1
Transitive dependencies
stack_trace 1.9.5
Dev dependencies
path ^1.7.0 1.7.0
pedantic ^1.9.0
test ^1.15.0
test_coverage ^0.4.1