Add unit tests; When pull request do not run integration tests
This commit is contained in:
parent
3a22fa65e7
commit
a35fb4188e
58
.github/workflows/deploy_docs.yml
vendored
58
.github/workflows/deploy_docs.yml
vendored
|
@ -1,58 +0,0 @@
|
|||
name: Deploy docs
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
package-name:
|
||||
description: 'Package name'
|
||||
default: 'nyxx'
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
build-docs:
|
||||
name: Build and upload docs
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.4
|
||||
|
||||
- name: Setup Dart Action
|
||||
uses: cedx/setup-dart@v2.3.0
|
||||
with:
|
||||
release-channel: dev
|
||||
|
||||
- name: Create temp docs dir
|
||||
run: mkdir /tmp/temp_docs
|
||||
|
||||
- name: Build nyxx docs
|
||||
working-directory: ./nyxx
|
||||
run: dartdoc --enable-experiment=non-nullable
|
||||
|
||||
- name: Move nyxx docs to shared directory
|
||||
working-directory: ./nyxx
|
||||
run: cp -R ./doc/api /tmp/temp_docs/nyxx
|
||||
|
||||
- name: Build nyxx.commander docs
|
||||
working-directory: ./nyxx.commander
|
||||
run: dartdoc --enable-experiment=non-nullable
|
||||
|
||||
- name: Move nyxx docs to shared directory
|
||||
working-directory: ./nyxx.commander
|
||||
run: cp -R ./doc/api /tmp/temp_docs/nyxx.commander
|
||||
|
||||
- name: Build nyxx.extensions docs
|
||||
working-directory: ./nyxx.extensions
|
||||
run: dartdoc --enable-experiment=non-nullable
|
||||
|
||||
- name: Move nyxx docs to shared directory
|
||||
working-directory: ./nyxx.extensions
|
||||
run: cp -R ./doc/api /tmp/temp_docs/nyxx.extensions
|
||||
|
||||
- name: GitHub Pages action
|
||||
uses: peaceiris/actions-gh-pages@v3.7.3
|
||||
with:
|
||||
github_token: ${{ secrets.ACCESS_TOKEN }}
|
||||
# personal_token: # optional
|
||||
publish_dir: /tmp/temp_docs
|
||||
destination_dir: ./
|
||||
user_name: l7ssha
|
||||
user_email: szymon@l7ssha.xyz
|
34
.github/workflows/publish.yml
vendored
34
.github/workflows/publish.yml
vendored
|
@ -1,34 +0,0 @@
|
|||
name: Deploy to pub
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
package-name:
|
||||
description: 'Package name'
|
||||
default: 'nyxx'
|
||||
required: true
|
||||
dry:
|
||||
description: 'True if dry run, or false to publish'
|
||||
default: 'true'
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
name: Publish package
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.4
|
||||
|
||||
- name: Setup Dart Action
|
||||
uses: cedx/setup-dart@v2.3.0
|
||||
with:
|
||||
release-channel: dev
|
||||
|
||||
- name: Publish
|
||||
uses: sakebook/actions-flutter-pub-publisher@v1.3.1
|
||||
with:
|
||||
credential: ${{ secrets.CREDENTIAL_JSON }}
|
||||
package_directory: ${{ github.event.inputs.package-name }}
|
||||
flutter_package: false
|
||||
skip_test: true
|
||||
dry_run: true
|
12
.github/workflows/tests.yml
vendored
12
.github/workflows/tests.yml
vendored
|
@ -30,14 +30,20 @@ jobs:
|
|||
- name: Analyze project source
|
||||
working-directory: ./nyxx
|
||||
run: dart analyze
|
||||
|
||||
|
||||
- name: Unit tests
|
||||
working-directory: ./nyxx/test
|
||||
run: dart run test unit.dart
|
||||
|
||||
- name: Compile tests
|
||||
working-directory: ./nyxx/test
|
||||
run: dart2native --enable-experiment=non-nullable travis.dart
|
||||
if: github.event_name != 'pull_request'
|
||||
|
||||
- name: Run tests
|
||||
working-directory: ./nyxx/test
|
||||
run: ./travis.exe
|
||||
if: github.event_name != 'pull_request'
|
||||
|
||||
test-commander:
|
||||
name: Tests commander package
|
||||
|
@ -71,10 +77,12 @@ jobs:
|
|||
- name: Compile tests
|
||||
working-directory: ./nyxx.commander/test
|
||||
run: dart2native --enable-experiment=non-nullable commander-test.dart
|
||||
if: github.event_name != 'pull_request'
|
||||
|
||||
- name: Run tests
|
||||
working-directory: ./nyxx.commander/test
|
||||
run: ./commander-test.exe
|
||||
if: github.event_name != 'pull_request'
|
||||
|
||||
test-extensions:
|
||||
name: Tests extensions package
|
||||
|
@ -108,7 +116,9 @@ jobs:
|
|||
- name: Compile tests
|
||||
working-directory: ./nyxx.extensions/test
|
||||
run: dart2native --enable-experiment=non-nullable extensions-tests.dart
|
||||
if: github.event_name != 'pull_request'
|
||||
|
||||
- name: Run tests
|
||||
working-directory: ./nyxx.extensions/test
|
||||
run: ./extensions-tests.exe
|
||||
if: github.event_name != 'pull_request'
|
||||
|
|
|
@ -21,6 +21,7 @@ class SnowflakeEntity {
|
|||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
if (other is SnowflakeEntity) return id == other.id;
|
||||
if (other is Snowflake) return id == other;
|
||||
if (other is String) return id.id.toString() == other;
|
||||
if (other is int) return id.id == other;
|
||||
|
||||
|
|
|
@ -11,9 +11,6 @@ class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns extension of file from specified [path]
|
||||
static String getFileExtension(String path) => path_utils.Context(style: path_utils.Style.platform).extension(path);
|
||||
|
||||
/// Returns String with base64 encoded image data for API upload
|
||||
static String? getBase64UploadString({File? file, List<int>? fileBytes, String? base64EncodedFile, String? fileExtension}) {
|
||||
String base64Encoded;
|
||||
|
@ -27,7 +24,7 @@ class Utils {
|
|||
return null;
|
||||
}
|
||||
|
||||
final extension = file != null ? path_utils.extension(file.path) : fileExtension;
|
||||
final extension = file != null ? path_utils.extension(file.path).replaceAll(".", "") : fileExtension;
|
||||
return "data:image/$extension;base64,$base64Encoded";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,3 +13,6 @@ dependencies:
|
|||
logging: "^1.0.0-nullsafety.0"
|
||||
http: "^0.13.0"
|
||||
path: "^1.8.0-nullsafety.3"
|
||||
|
||||
dev_dependencies:
|
||||
test: "^1.16.2"
|
||||
|
|
91
nyxx/test/unit.dart
Normal file
91
nyxx/test/unit.dart
Normal file
|
@ -0,0 +1,91 @@
|
|||
import "dart:convert";
|
||||
import "dart:io";
|
||||
|
||||
import "package:nyxx/nyxx.dart";
|
||||
import "package:test/test.dart";
|
||||
|
||||
const snowflakeAYear = 2017;
|
||||
const snowflakeBYear = 2018;
|
||||
|
||||
void main() {
|
||||
final snowflakeA = Snowflake.fromDateTime(DateTime.utc(snowflakeAYear));
|
||||
final snowflakeB = Snowflake.fromDateTime(DateTime.utc(snowflakeBYear));
|
||||
|
||||
group("Snowflake tests", () {
|
||||
test("Snowflakes should have correct date", () {
|
||||
expect(snowflakeA.timestamp.year, snowflakeAYear);
|
||||
expect(snowflakeB.timestamp.year, snowflakeBYear);
|
||||
});
|
||||
|
||||
test("Snowflake A should have timestamp before Snowflake B", () {
|
||||
expect(snowflakeA.isBefore(snowflakeB), true);
|
||||
expect(snowflakeB.isAfter(snowflakeA), true);
|
||||
});
|
||||
|
||||
test("Snowflake.fromNow() returns valid snowflake", () {
|
||||
final snowflake = Snowflake.fromNow();
|
||||
final now = DateTime.now();
|
||||
|
||||
expect(snowflake.timestamp.compareTo(now), -1);
|
||||
});
|
||||
|
||||
test("Snowflake compareDates returns valid results", () {
|
||||
expect(Snowflake.compareDates(snowflakeA, snowflakeB), -1);
|
||||
expect(Snowflake.compareDates(snowflakeB, snowflakeA), 1);
|
||||
|
||||
final snowflakeAClone = Snowflake.fromDateTime(DateTime.utc(snowflakeAYear));
|
||||
|
||||
expect(Snowflake.compareDates(snowflakeA, snowflakeAClone), 0);
|
||||
});
|
||||
|
||||
test("Snowflake equality", () {
|
||||
const snowflakeValue = 123;
|
||||
final snowflake = snowflakeValue.toSnowflake();
|
||||
final snowflake2 = snowflakeValue.toSnowflake();
|
||||
|
||||
expect(snowflake.id, snowflakeValue);
|
||||
|
||||
expect(snowflake == snowflakeValue, true);
|
||||
expect(snowflake2 == snowflake, true);
|
||||
expect(snowflake == snowflakeValue.toString(), true);
|
||||
|
||||
expect(snowflake == 125, false);
|
||||
});
|
||||
});
|
||||
|
||||
test("SnowflakeEntity equality", () {
|
||||
final snowflakeEntityA = SnowflakeEntity(snowflakeA);
|
||||
|
||||
expect(snowflakeEntityA.id == snowflakeA, true);
|
||||
expect(snowflakeEntityA.createdAt == snowflakeA.timestamp, true);
|
||||
|
||||
expect(snowflakeEntityA == snowflakeA, true);
|
||||
});
|
||||
|
||||
group("Generic utils", () {
|
||||
test("Utils.getBase64UploadString returns valid string", () {
|
||||
final kittyFile = File("./test/kitty.webp");
|
||||
const extension = "webp";
|
||||
|
||||
final encodedKitty = base64Encode(kittyFile.readAsBytesSync());
|
||||
|
||||
final expectedStringFile = "data:image/$extension;base64,$encodedKitty";
|
||||
expect(Utils.getBase64UploadString(file: kittyFile, fileExtension: extension), expectedStringFile);
|
||||
expect(Utils.getBase64UploadString(fileBytes: kittyFile.readAsBytesSync(), fileExtension: extension), expectedStringFile);
|
||||
expect(Utils.getBase64UploadString(base64EncodedFile: encodedKitty, fileExtension: extension), expectedStringFile);
|
||||
}, skip: "Skipped for now because of problems with required path to file");
|
||||
|
||||
test("Utils.chunk returns valid chunks", () async {
|
||||
final testList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
final chunks = Utils.chunk(testList, 2);
|
||||
|
||||
expect(chunks, emitsInOrder([
|
||||
[0, 1],
|
||||
[2, 3],
|
||||
[4, 5],
|
||||
[6, 7],
|
||||
[8, 9]
|
||||
]));
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue