Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Commit

Permalink
Merge pull request #189 from devoncarew/devoncarew_add_web_tests
Browse files Browse the repository at this point in the history
Add web tests
  • Loading branch information
devoncarew committed Dec 20, 2014
2 parents 9de3209 + f7ec98c commit a9cfaa4
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 8 deletions.
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies:
uuid: '>=0.4.0 <0.5.0'

dev_dependencies:
browser: any
ghpages_generator: any
grinder: '>=0.6.0 <0.7.0'
unittest: any
2 changes: 0 additions & 2 deletions test/cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import 'package:stagehand/src/cli_app.dart';
import 'package:unittest/unittest.dart';
import 'package:usage/usage.dart';

void main() => defineTests();

void defineTests() {
group('cli', () {
CliApp app;
Expand Down
9 changes: 5 additions & 4 deletions test/common_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ library stagehand.common_test;
import 'package:stagehand/src/common.dart';
import 'package:unittest/unittest.dart';

void main() => defineTests();

void defineTests() {
group('common', () {
test('normalizeProjectName', () {
Expand All @@ -31,8 +29,11 @@ void defineTests() {

test('convertToYamlMultiLine', () {
expect(
convertToYamlMultiLine('one two three four five size seven eight nine ten eleven twelve thirteen fourteen fifteen'),
' one two three four five size seven eight nine ten eleven twelve thirteen\n fourteen fifteen');
convertToYamlMultiLine(
'one two three four five size seven eight nine '
'ten eleven twelve thirteen fourteen fifteen'),
' one two three four five size seven eight nine ten eleven twelve '
'thirteen\n fourteen fifteen');
});
});
}
Expand Down
2 changes: 0 additions & 2 deletions test/generators_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ library stagehand.generators_test;
import 'package:stagehand/stagehand.dart';
import 'package:unittest/unittest.dart';

void main() => defineTests();

void defineTests() {
group('generators', () {
generators.forEach((generator) {
Expand Down
19 changes: 19 additions & 0 deletions test/web.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>

<!-- Copyright (c) 2014, Google Inc. 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. -->

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stagehand Tests</title>
</head>

<body>
<script src="packages/unittest/test_controller.js"></script>
<script type="application/dart" src="web_test.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
63 changes: 63 additions & 0 deletions test/web_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2014, Google Inc. 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.

library stagehand.web_test;

import 'dart:async';

import 'package:stagehand/stagehand.dart';
import 'package:unittest/html_config.dart';
import 'package:unittest/unittest.dart';

import 'common_test.dart' as common_test;
import 'generators_test.dart' as generators_test;

// TODO: get the tests running in content_shell

void main() {
// Set up the test environment.
useHtmlConfiguration();

// Define the tests.
common_test.defineTests();
generators_test.defineTests();
defineIntegrationTests();
}

void defineIntegrationTests() {
group('integration', () {
generators.forEach((generator) {
test(generator.id, () => testGenerator(getGenerator(generator.id)));
});
});
}

Future testGenerator(Generator generator) {
expect(generator.id, isNotNull);

MockTarget target = new MockTarget();

// Assert that we can generate the template.
return generator.generate('foo', target).then((_) {
// Run some basic validation on the generated results.
expect(target.getFileContentsAsString('.gitignore'), isNotNull);
expect(target.getFileContentsAsString('pubspec.yaml'), isNotNull);
});
}

class MockTarget extends GeneratorTarget {
Map<String, List<int>> files = {};

Future createFile(String path, List<int> contents) {
files[path] = contents;
return new Future.value();
}

bool hasFile(String path) => files.containsKey(path);

String getFileContentsAsString(String path) {
if (!hasFile(path)) return null;
return new String.fromCharCodes(files[path]);
}
}

0 comments on commit a9cfaa4

Please sign in to comment.