Git Product home page Git Product logo

clock's People

Contributors

athomas avatar cbracken avatar dependabot[bot] avatar devoncarew avatar jakemac53 avatar justinfagnani avatar keertip avatar kevmoo avatar michaelrfairhurst avatar munificent avatar natebosch avatar nex3 avatar pq avatar srawlins avatar stereotype441 avatar wills avatar yjbanov avatar zoechigist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clock's Issues

How to remove this lint message

info: The imported package 'clock' isn't a dependency of the importing package. (depend_on_referenced_packages at [AppName] test/path/to/hoge_test.dart:4)

But pubspec.yaml file, I added this.

dependencies:
  clock: ^1.1.1

clock.now() returns different time in a new BuildContext

If I use withClock with a fixed time, I get a different time if I use it in a new BuildContext in WidgetTesting. I expect that all of the test should have the fixed time I set with withClock.
Here is a small example.

import 'package:clock/clock.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:golden_toolkit/golden_toolkit.dart';

void main() {
  final fixedClock = Clock.fixed(DateTime(2023));

  setUpAll(loadAppFonts);

  testWidgets('Test clock with raw widget', (tester) async {
    // returns 2023-01-01
    final widget = withClock(
      fixedClock,
      () => MaterialApp(
        home: Scaffold(
          body: Center(child: Text(clock.now().toString())),
        ),
      ),
    );

    await tester.pumpWidget(widget);
    await expectLater(
      find.byType(MaterialApp),
      matchesGoldenFile('raw_widget.png'),
    );
  });

  testWidgets('Test clock with builder', (tester) async {
    // returns 2023-04-24 
    final widget = withClock(
      fixedClock,
      () => MaterialApp(
        home: Scaffold(
          body: Center(
            child: Builder(
              builder: (context) => Text(
                clock.now().toString(),
              ),
            ),
          ),
        ),
      ),
    );

    await tester.pumpWidget(widget);
    await expectLater(
      find.byType(MaterialApp),
      matchesGoldenFile('builder.png'),
    );
  });

  testWidgets(
    'Test widget with clock only wrapped around widget',
    (tester) async {
      // returns 2023-04-24
      final widget = withClock(
        fixedClock,
        TestWidget.new,
      );

      await tester.pumpWidget(widget);
      await expectLater(
        find.byType(MaterialApp),
        matchesGoldenFile('clock_wrap_widget_.png'),
      );
    },
  );

  testWidgets(
    'Test widget with clock wrapped around whole test content',
    (tester) async {
      // returns 2023-01-01
      await withClock(fixedClock, () async {
        final widget = withClock(
          fixedClock,
          TestWidget.new,
        );

        await tester.pumpWidget(widget);
        await expectLater(
          find.byType(MaterialApp),
          matchesGoldenFile('clock_wrap_test_content.png'),
        );
      });
    },
  );
}

class TestWidget extends StatelessWidget {
  const TestWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Text(clock.now().toString()),
        ),
      ),
    );
  }
}

Change of Copyright notice

Hello! According to the Appendix of Apache License 2.0, if you want to license your software under this License you should "attach the boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information". This condition is not met now. Please add a copyright notice in the appropriate form, including the year of the software development and your name and surname. Thank you in advance

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Tests not running on travis

clock/.travis.yml

Lines 12 to 24 in b49aa83

dart_task:
- test: --platform vm
# Uncomment this line to run tests on the browser.
# - test: --platform firefox
# Only run one instance of the formatter and the analyzer, rather than running
# them against each Dart version.
matrix:
include:
- dart: dev
dart_task: dartanalyzer
- dart: dev
dart_task: dartfmt

Only analyzer and dartfmt

Thoughts @munificent @nex3 ?

Clarify copyright holder

I'm trying to figure out who the copyright holder is for this package.

CONTRIBUTING.md instructs contributors to us a copyright in the source files of:
Copyright (c) 2017, the Dart project authors.
but the source files actually have copyrights for Google Inc., the pub spec has an author of "Dart Team", and the LICENSE file does not contain a copyright.

Many open source packages have a copyright statement at the beginning of the LICENSE file which is what I'd suggest if possible.

Thanks

withClock() behaves inconsistently with test()

Consider this code:

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

void main() {
  final fakeClock = Clock.fixed(DateTime(2020, 1, 1));

  test('inner withClock', () {
    withClock(fakeClock, () {
      expect(clock, same(fakeClock));
    });
  });

  withClock(fakeClock, () {
    test('outer withClock', () {
      expect(clock, same(fakeClock));
    });
  });
}

I don't see anything in the withClock documentation that indicates whether one form is preferred over the other. When I run this with dart this_test.dart, I get:

00:00 +0: inner withClock
00:00 +1: outer withClock
00:00 +1 -1: outer withClock [E]

  Expected: same instance as <Instance of 'Clock'>
    Actual: <Instance of 'Clock'>

More weirdness, part 1

If I reverse the tests, they pass when running it through dart.

More weirdness, part 2

The "outer withClock" test by itself fails with flutter test or with pub run test. Each test passes individually when run directly through dart.

Ultimately I'd like to do:

withClock(fakeClock, () {
  test(...);
  test(...);
  test(...);
});

but all of this weirdness seems to prevent that.

(I'm using Dart 2.8.1 with clock 1.0.1.)

Flutter's WidgetsFlutterBinding.ensureInitialized() and withClock() - causes clock.now() to misbehave

If flutter app starts with:

void main() {
  WidgetsFlutterBinding.ensureInitialized();

Then clock.now() prints not mocked value if outside of build method.

Minimum reproduceable code:

import 'package:clock/clock.dart';
import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  
  withClock(Clock.fixed(DateTime(1990)), () {
    runApp(const MyApp());
  });
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  void _printClockNow() {
    print('_printClockNow is: ${clock.now()}'); // prints real NOW
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    print('build clock.now() is: ${clock.now()}'); // prints mocked NOW

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[Dummy()],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _printClockNow,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

class Dummy extends StatelessWidget {
  @override
  Widget build(Object context) {
    return Text('t: ${clock.now()}');
  }
}

Expected behavior:
clock.now() to have mocked value despite WidgetsFlutterBinding.ensureInitialized()

EDIT:
Changed because I discovered that culprit is WidgetsFlutterBinding.ensureInitialized().

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.