Skip to content

Run tests on browser #199

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

Merged
merged 4 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Created with https://github.com/dart-lang/mono_repo
language: dart

####################
# Begin hand edits #
####################
sudo: required
addons:
chrome: stable
##################
# End hand edits #
##################

jobs:
include:
- stage: analyzer_and_format
Expand Down Expand Up @@ -35,6 +45,10 @@ jobs:
script: ./tool/travis.sh test
env: PKG="json_serializable"
dart: dev
- stage: unit_test
script: ./tool/travis.sh command
env: PKG="json_serializable"
dart: dev

stages:
- analyzer_and_format
Expand Down
1 change: 1 addition & 0 deletions json_serializable/.mono_repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ stages:
- unit_test:
# Run the tests -- include the default-skipped presubmit tests
- test: --run-skipped
- command: pub run build_runner test -- -p chrome
9 changes: 9 additions & 0 deletions json_serializable/build.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
targets:
$default:
builders:
build_web_compilers|entrypoint:
generate_for:
- test/default_value/**
- test/json_serializable_integration*
- test/kitchen_sink/**

# Read about `build.yaml` at https://pub.dartlang.org/packages/build_config
builders:
json_serializable:
Expand Down
1 change: 1 addition & 0 deletions json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
source_gen: '>=0.8.1 <0.9.0'
dev_dependencies:
build_runner: ^0.8.0
build_web_compilers: ^0.4.0+1
build_test: ">=0.9.0 <0.11.0"
collection: ^1.14.0
dart_style: ^1.0.0
Expand Down
2 changes: 2 additions & 0 deletions json_serializable/test/config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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.

@TestOn('vm')

import 'dart:async';
import 'dart:io';

Expand Down
2 changes: 2 additions & 0 deletions json_serializable/test/ensure_build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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.

@TestOn('vm')

import 'dart:convert';
import 'dart:io';

Expand Down
2 changes: 2 additions & 0 deletions json_serializable/test/enum_helper_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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.

@TestOn('vm')

import 'package:test/test.dart';
import 'package:json_serializable/src/type_helpers/enum_helper.dart';

Expand Down
4 changes: 2 additions & 2 deletions json_serializable/test/generic_files/generic_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class GenericClass<T extends num, S> extends Object
_$GenericClassFromJson<T, S>(json);
}

T _dataFromJson<T, S, U>(Map<String, dynamic> input, [S other1, U, other2]) =>
T _dataFromJson<T, S, U>(Map<String, dynamic> input, [S other1, U other2]) =>
input['value'] as T;

Map<String, dynamic> _dataToJson<T, S, U>(T input, [S other1, U, other2]) =>
Map<String, dynamic> _dataToJson<T, S, U>(T input, [S other1, U other2]) =>
{'value': input};
11 changes: 6 additions & 5 deletions json_serializable/test/json_literal_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
// 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.

@TestOn('vm')

import 'dart:convert';
import 'dart:io';

import 'package:test/test.dart';
import 'package:path/path.dart' as p;

import 'test_file_utils.dart';
import 'test_files/json_literal.dart';
import 'test_utils.dart';

main() {
test('literal round-trip', () {
var dataFilePath =
p.join(getPackagePath(), 'test', 'test_files', 'json_literal.json');
var dataFilePath = testFilePath('test', 'test_files', 'json_literal.json');
var dataFile = new File(dataFilePath);

var dataString = loudEncode(json.decode(dataFile.readAsStringSync()));
Expand All @@ -27,8 +28,8 @@ main() {
});

test('naughty strings', () {
var dataFilePath = p.join(getPackagePath(), 'test', 'test_files',
'big-list-of-naughty-strings.json');
var dataFilePath =
testFilePath('test', 'test_files', 'big-list-of-naughty-strings.json');
var dataFile = new File(dataFilePath);

var dataString = loudEncode(json.decode(dataFile.readAsStringSync()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void main() {
test('with bad arguments', () {
expect(
() => new GenericClass<double, String>()
..fieldT = (5 as dynamic) as double,
..fieldT = (true as dynamic) as double,
throwsA(isACastError));
});
test('with bad arguments', () {
Expand Down Expand Up @@ -184,9 +184,9 @@ void main() {

test('custom DateTime', () {
var instance = new Numbers()
..date = new DateTime.fromMicrosecondsSinceEpoch(42);
..date = new DateTime.fromMillisecondsSinceEpoch(42);
var json = instance.toJson();
expect(json, containsPair('date', 42));
expect(json, containsPair('date', 42000));
});

test('support ints as doubles', () {
Expand All @@ -200,7 +200,7 @@ void main() {

test('does not support doubles as ints', () {
var value = {
'ints': [0.0, 0],
'ints': [3.14, 0],
};

expect(() => new Numbers.fromJson(value),
Expand Down
10 changes: 3 additions & 7 deletions json_serializable/test/json_serializable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@
// 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.

@TestOn('!browser')
library json_serializable.test.json_generator_test;

// TODO(kevmoo): test all flavors of `nullable` - class, fields, etc
@TestOn('vm')

import 'dart:async';

import 'package:analyzer/dart/ast/ast.dart';
import 'package:dart_style/dart_style.dart' as dart_style;
import 'package:json_serializable/json_serializable.dart';
import 'package:json_serializable/src/constants.dart';
import 'package:path/path.dart' as p;
import 'package:source_gen/source_gen.dart';
import 'package:test/test.dart';

import 'analysis_utils.dart';
import 'test_file_utils.dart';
import 'test_utils.dart';

Matcher _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher) =>
Expand All @@ -36,8 +33,7 @@ CompilationUnit _compilationUnit;

void main() {
setUpAll(() async {
var path = p.join(
getPackagePath(), 'test', 'src', 'json_serializable_test_input.dart');
var path = testFilePath('test', 'src', 'json_serializable_test_input.dart');
_compilationUnit = await resolveCompilationUnit(path);
});

Expand Down
26 changes: 26 additions & 0 deletions json_serializable/test/test_file_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2018, 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 'dart:mirrors';

import 'package:path/path.dart' as p;

String testFilePath(String part1, [String part2, String part3]) =>
p.join(_packagePath(), part1, part2, part3);

String _packagePathCache;

String _packagePath() {
if (_packagePathCache == null) {
// Getting the location of this file – via reflection
var currentFilePath = (reflect(_packagePath) as ClosureMirror)
.function
.location
.sourceUri
.path;

_packagePathCache = p.normalize(p.join(p.dirname(currentFilePath), '..'));
}
return _packagePathCache;
}
18 changes: 0 additions & 18 deletions json_serializable/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,11 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';
import 'dart:mirrors';

import 'package:path/path.dart' as p;
import 'package:test/test.dart';

final isACastError = const isInstanceOf<CastError>();

String _packagePathCache;

String getPackagePath() {
if (_packagePathCache == null) {
// Getting the location of this file – via reflection
var currentFilePath = (reflect(getPackagePath) as ClosureMirror)
.function
.location
.sourceUri
.path;

_packagePathCache = p.normalize(p.join(p.dirname(currentFilePath), '..'));
}
return _packagePathCache;
}

// TODO(kevmoo) add this to pkg/matcher – is nice!
class FeatureMatcher<T> extends CustomMatcher {
final dynamic Function(T value) _feature;
Expand Down
2 changes: 2 additions & 0 deletions json_serializable/test/yaml/yaml_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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.

@TestOn('vm')

import 'dart:io';

import 'package:json_annotation/json_annotation.dart';
Expand Down
5 changes: 5 additions & 0 deletions tool/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ EXIT_CODE=0
while (( "$#" )); do
TASK=$1
case $TASK in
command) echo
echo -e '\033[1mTASK: command\033[22m'
echo -e 'pub run build_runner test -- -p chrome'
pub run build_runner test -- -p chrome || EXIT_CODE=$?
;;
dartanalyzer) echo
echo -e '\033[1mTASK: dartanalyzer\033[22m'
echo -e 'dartanalyzer --fatal-infos --fatal-warnings .'
Expand Down