Skip to content

Commit

Permalink
Run embedded test on both dart and node
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Nov 5, 2024
1 parent 28ae04c commit 8e78ca3
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 33 deletions.
16 changes: 16 additions & 0 deletions test/embedded/dart/file_importer_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

import 'package:test/test.dart';

import '../shared/file_importer.dart';
import '../dart_test.dart';

void main() {
setUpAll(ensureSnapshotUpToDate);
sharedTests(runSassEmbedded);
}
16 changes: 16 additions & 0 deletions test/embedded/dart/function_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

import 'package:test/test.dart';

import '../shared/function.dart';
import '../dart_test.dart';

void main() {
setUpAll(ensureSnapshotUpToDate);
sharedTests(runSassEmbedded);
}
16 changes: 16 additions & 0 deletions test/embedded/dart/importer_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

import 'package:test/test.dart';

import '../shared/importer.dart';
import '../dart_test.dart';

void main() {
setUpAll(ensureSnapshotUpToDate);
sharedTests(runSassEmbedded);
}
16 changes: 16 additions & 0 deletions test/embedded/dart/length_delimited_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

import 'package:test/test.dart';

import '../shared/length_delimited.dart';
import '../dart_test.dart';

void main() {
setUpAll(ensureSnapshotUpToDate);
sharedTests();
}
16 changes: 16 additions & 0 deletions test/embedded/dart/protocol_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

import 'package:test/test.dart';

import '../shared/protocol.dart';
import '../dart_test.dart';

void main() {
setUpAll(ensureSnapshotUpToDate);
sharedTests(runSassEmbedded);
}
22 changes: 22 additions & 0 deletions test/embedded/dart_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

import 'package:cli_pkg/testing.dart' as pkg;
import 'package:test/test.dart';

import 'shared/embedded_process.dart';

void main() {}

/// Ensures that the snapshot of the Dart executable used by [runSassEmbedded] is
/// up-to-date, if one has been generated.
void ensureSnapshotUpToDate() => pkg.ensureExecutableUpToDate("sass");

Future<EmbeddedProcess> runSassEmbedded(
[Iterable<String> args = const Iterable.empty()]) =>
EmbeddedProcess.start(pkg.executableRunner("sass"),
[...pkg.executableArgs("sass"), "--embedded", ...args]);
17 changes: 17 additions & 0 deletions test/embedded/node/file_importer_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
@Tags(['node'])
library;

import 'package:test/test.dart';

import '../shared/file_importer.dart';
import '../node_test.dart';

void main() {
setUpAll(ensureSnapshotUpToDate);
sharedTests(runSassEmbedded);
}
17 changes: 17 additions & 0 deletions test/embedded/node/function_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
@Tags(['node'])
library;

import 'package:test/test.dart';

import '../shared/function.dart';
import '../node_test.dart';

void main() {
setUpAll(ensureSnapshotUpToDate);
sharedTests(runSassEmbedded);
}
17 changes: 17 additions & 0 deletions test/embedded/node/importer_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
@Tags(['node'])
library;

import 'package:test/test.dart';

import '../shared/importer.dart';
import '../node_test.dart';

void main() {
setUpAll(ensureSnapshotUpToDate);
sharedTests(runSassEmbedded);
}
17 changes: 17 additions & 0 deletions test/embedded/node/length_delimited_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
@Tags(['node'])
library;

import 'package:test/test.dart';

import '../shared/length_delimited.dart';
import '../node_test.dart';

void main() {
setUpAll(ensureSnapshotUpToDate);
sharedTests();
}
17 changes: 17 additions & 0 deletions test/embedded/node/protocol_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
@Tags(['node'])
library;

import 'package:test/test.dart';

import '../shared/protocol.dart';
import '../node_test.dart';

void main() {
setUpAll(ensureSnapshotUpToDate);
sharedTests(runSassEmbedded);
}
24 changes: 24 additions & 0 deletions test/embedded/node_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 Google LLC. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
@Tags(['node'])
library;

import 'package:cli_pkg/testing.dart' as pkg;
import 'package:test/test.dart';

import '../ensure_npm_package.dart';
import 'shared/embedded_process.dart';

void main() {}

/// Ensures that the snapshot of the npm package used by [runSassEmbedded] is
/// up-to-date, if one has been generated.
void ensureSnapshotUpToDate() => ensureNpmPackage;

Future<EmbeddedProcess> runSassEmbedded(
[Iterable<String> args = const Iterable.empty()]) =>
EmbeddedProcess.start(pkg.executableRunner("sass", node: true),
[...pkg.executableArgs("sass", node: true), "--embedded", ...args]);
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

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

import 'package:async/async.dart';
import 'package:cli_pkg/testing.dart' as pkg;
import 'package:test/test.dart';

import 'package:sass/src/embedded/embedded_sass.pb.dart';
Expand Down Expand Up @@ -85,14 +81,13 @@ class EmbeddedProcess {
/// If [forwardOutput] is `true`, the process's [outbound] messages and
/// [stderr] will be printed to the console as they appear. This is only
/// intended to be set temporarily to help when debugging test failures.
static Future<EmbeddedProcess> start(
static Future<EmbeddedProcess> start(String command, List<String> args,
{String? workingDirectory,
Map<String, String>? environment,
bool includeParentEnvironment = true,
bool runInShell = false,
bool forwardOutput = false}) async {
var process = await Process.start(pkg.executableRunner("sass"),
[...pkg.executableArgs("sass"), "--embedded"],
var process = await Process.start(command, args,
workingDirectory: workingDirectory,
environment: environment,
includeParentEnvironment: includeParentEnvironment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;
Expand All @@ -15,10 +12,10 @@ import 'package:sass/src/embedded/utils.dart';
import 'embedded_process.dart';
import 'utils.dart';

void main() {
void sharedTests(Future<EmbeddedProcess> runSassEmbedded()) {
late EmbeddedProcess process;
setUp(() async {
process = await EmbeddedProcess.start();
process = await runSassEmbedded();
});

group("emits a protocol error", () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

import 'package:test/test.dart';

import 'package:sass/src/embedded/embedded_sass.pb.dart';
Expand All @@ -19,9 +16,9 @@ final _null = Value()..singleton = SingletonValue.NULL;

late EmbeddedProcess _process;

void main() {
void sharedTests(Future<EmbeddedProcess> runSassEmbedded()) async {
setUp(() async {
_process = await EmbeddedProcess.start();
_process = await runSassEmbedded();
});

group("emits a compile failure for a custom function with a signature", () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

import 'package:source_maps/source_maps.dart' as source_maps;
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;
Expand All @@ -15,10 +12,10 @@ import 'package:sass/src/embedded/utils.dart';
import 'embedded_process.dart';
import 'utils.dart';

void main() {
void sharedTests(Future<EmbeddedProcess> runSassEmbedded()) {
late EmbeddedProcess process;
setUp(() async {
process = await EmbeddedProcess.start();
process = await runSassEmbedded();
});

group("emits a protocol error", () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

import 'dart:async';
import 'dart:typed_data';

Expand All @@ -13,7 +10,7 @@ import 'package:sass/src/embedded/util/length_delimited_transformer.dart';
import 'package:async/async.dart';
import 'package:test/test.dart';

void main() {
void sharedTests() {
group("encoder", () {
late Sink<List<int>> sink;
late Stream<List<int>> stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

@TestOn('vm')
library;

import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';
import 'package:source_maps/source_maps.dart' as source_maps;
Expand All @@ -17,10 +14,10 @@ import 'package:sass/src/embedded/utils.dart';
import 'embedded_process.dart';
import 'utils.dart';

void main() {
void sharedTests(Future<EmbeddedProcess> runSassEmbedded()) {
late EmbeddedProcess process;
setUp(() async {
process = await EmbeddedProcess.start();
process = await runSassEmbedded();
});

group("exits upon protocol error", () {
Expand Down Expand Up @@ -454,8 +451,15 @@ void main() {
(InboundMessage_CompileRequest()..path = d.path("test.scss")));

var failure = await getCompileFailure(process);
expect(failure.message, startsWith("Cannot open file: "));
expect(failure.message.replaceFirst("Cannot open file: ", "").trim(),
expect(
failure.message,
anyOf(startsWith("Cannot open file: "),
startsWith("no such file or directory: ")));
expect(
failure.message
.replaceFirst("Cannot open file: ", "")
.replaceFirst("no such file or directory: ", "")
.trim(),
equalsPath(d.path('test.scss')));
expect(failure.span.text, equals(''));
expect(failure.span.context, equals(''));
Expand Down
File renamed without changes.

0 comments on commit 8e78ca3

Please sign in to comment.