Skip to content

Commit 7ffed6e

Browse files
committed
Run embedded test on both dart and node
1 parent 54fabf3 commit 7ffed6e

19 files changed

+231
-33
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
library;
7+
8+
import 'package:test/test.dart';
9+
10+
import '../shared/file_importer.dart';
11+
import '../dart_test.dart';
12+
13+
void main() {
14+
setUpAll(ensureSnapshotUpToDate);
15+
sharedTests(runSassEmbedded);
16+
}

test/embedded/dart/function_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
library;
7+
8+
import 'package:test/test.dart';
9+
10+
import '../shared/function.dart';
11+
import '../dart_test.dart';
12+
13+
void main() {
14+
setUpAll(ensureSnapshotUpToDate);
15+
sharedTests(runSassEmbedded);
16+
}

test/embedded/dart/importer_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
library;
7+
8+
import 'package:test/test.dart';
9+
10+
import '../shared/importer.dart';
11+
import '../dart_test.dart';
12+
13+
void main() {
14+
setUpAll(ensureSnapshotUpToDate);
15+
sharedTests(runSassEmbedded);
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
library;
7+
8+
import 'package:test/test.dart';
9+
10+
import '../shared/length_delimited.dart';
11+
import '../dart_test.dart';
12+
13+
void main() {
14+
setUpAll(ensureSnapshotUpToDate);
15+
sharedTests();
16+
}

test/embedded/dart/protocol_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
library;
7+
8+
import 'package:test/test.dart';
9+
10+
import '../shared/protocol.dart';
11+
import '../dart_test.dart';
12+
13+
void main() {
14+
setUpAll(ensureSnapshotUpToDate);
15+
sharedTests(runSassEmbedded);
16+
}

test/embedded/dart_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
library;
7+
8+
import 'package:cli_pkg/testing.dart' as pkg;
9+
import 'package:test/test.dart';
10+
11+
import 'shared/embedded_process.dart';
12+
13+
void main() {}
14+
15+
/// Ensures that the snapshot of the Dart executable used by [runSassEmbedded] is
16+
/// up-to-date, if one has been generated.
17+
void ensureSnapshotUpToDate() => pkg.ensureExecutableUpToDate("sass");
18+
19+
Future<EmbeddedProcess> runSassEmbedded(
20+
[Iterable<String> args = const Iterable.empty()]) =>
21+
EmbeddedProcess.start(pkg.executableRunner("sass"),
22+
[...pkg.executableArgs("sass"), "--embedded", ...args]);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
@Tags(['node'])
7+
library;
8+
9+
import 'package:test/test.dart';
10+
11+
import '../shared/file_importer.dart';
12+
import '../node_test.dart';
13+
14+
void main() {
15+
setUpAll(ensureSnapshotUpToDate);
16+
sharedTests(runSassEmbedded);
17+
}

test/embedded/node/function_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
@Tags(['node'])
7+
library;
8+
9+
import 'package:test/test.dart';
10+
11+
import '../shared/function.dart';
12+
import '../node_test.dart';
13+
14+
void main() {
15+
setUpAll(ensureSnapshotUpToDate);
16+
sharedTests(runSassEmbedded);
17+
}

test/embedded/node/importer_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
@Tags(['node'])
7+
library;
8+
9+
import 'package:test/test.dart';
10+
11+
import '../shared/importer.dart';
12+
import '../node_test.dart';
13+
14+
void main() {
15+
setUpAll(ensureSnapshotUpToDate);
16+
sharedTests(runSassEmbedded);
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
@Tags(['node'])
7+
library;
8+
9+
import 'package:test/test.dart';
10+
11+
import '../shared/length_delimited.dart';
12+
import '../node_test.dart';
13+
14+
void main() {
15+
setUpAll(ensureSnapshotUpToDate);
16+
sharedTests();
17+
}

test/embedded/node/protocol_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
@Tags(['node'])
7+
library;
8+
9+
import 'package:test/test.dart';
10+
11+
import '../shared/protocol.dart';
12+
import '../node_test.dart';
13+
14+
void main() {
15+
setUpAll(ensureSnapshotUpToDate);
16+
sharedTests(runSassEmbedded);
17+
}

test/embedded/node_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
@TestOn('vm')
6+
@Tags(['node'])
7+
library;
8+
9+
import 'package:cli_pkg/testing.dart' as pkg;
10+
import 'package:test/test.dart';
11+
12+
import '../ensure_npm_package.dart';
13+
import 'shared/embedded_process.dart';
14+
15+
void main() {}
16+
17+
/// Ensures that the snapshot of the npm package used by [runSassEmbedded] is
18+
/// up-to-date, if one has been generated.
19+
void ensureSnapshotUpToDate() => ensureNpmPackage;
20+
21+
Future<EmbeddedProcess> runSassEmbedded(
22+
[Iterable<String> args = const Iterable.empty()]) =>
23+
EmbeddedProcess.start(pkg.executableRunner("sass", node: true),
24+
[...pkg.executableArgs("sass", node: true), "--embedded", ...args]);

test/embedded/embedded_process.dart renamed to test/embedded/shared/embedded_process.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
@TestOn('vm')
6-
library;
7-
85
import 'dart:async';
96
import 'dart:convert';
107
import 'dart:io';
118

129
import 'package:async/async.dart';
13-
import 'package:cli_pkg/testing.dart' as pkg;
1410
import 'package:test/test.dart';
1511

1612
import 'package:sass/src/embedded/embedded_sass.pb.dart';
@@ -85,14 +81,13 @@ class EmbeddedProcess {
8581
/// If [forwardOutput] is `true`, the process's [outbound] messages and
8682
/// [stderr] will be printed to the console as they appear. This is only
8783
/// intended to be set temporarily to help when debugging test failures.
88-
static Future<EmbeddedProcess> start(
84+
static Future<EmbeddedProcess> start(String command, List<String> args,
8985
{String? workingDirectory,
9086
Map<String, String>? environment,
9187
bool includeParentEnvironment = true,
9288
bool runInShell = false,
9389
bool forwardOutput = false}) async {
94-
var process = await Process.start(pkg.executableRunner("sass"),
95-
[...pkg.executableArgs("sass"), "--embedded"],
90+
var process = await Process.start(command, args,
9691
workingDirectory: workingDirectory,
9792
environment: environment,
9893
includeParentEnvironment: includeParentEnvironment,

test/embedded/file_importer_test.dart renamed to test/embedded/shared/file_importer.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
@TestOn('vm')
6-
library;
7-
85
import 'package:path/path.dart' as p;
96
import 'package:test/test.dart';
107
import 'package:test_descriptor/test_descriptor.dart' as d;
@@ -15,10 +12,10 @@ import 'package:sass/src/embedded/utils.dart';
1512
import 'embedded_process.dart';
1613
import 'utils.dart';
1714

18-
void main() {
15+
void sharedTests(Future<EmbeddedProcess> runSassEmbedded()) {
1916
late EmbeddedProcess process;
2017
setUp(() async {
21-
process = await EmbeddedProcess.start();
18+
process = await runSassEmbedded();
2219
});
2320

2421
group("emits a protocol error", () {

test/embedded/function_test.dart renamed to test/embedded/shared/function.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
@TestOn('vm')
6-
library;
7-
85
import 'package:test/test.dart';
96

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

2017
late EmbeddedProcess _process;
2118

22-
void main() {
19+
void sharedTests(Future<EmbeddedProcess> runSassEmbedded()) async {
2320
setUp(() async {
24-
_process = await EmbeddedProcess.start();
21+
_process = await runSassEmbedded();
2522
});
2623

2724
group("emits a compile failure for a custom function with a signature", () {

test/embedded/importer_test.dart renamed to test/embedded/shared/importer.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
@TestOn('vm')
6-
library;
7-
85
import 'package:source_maps/source_maps.dart' as source_maps;
96
import 'package:test/test.dart';
107
import 'package:test_descriptor/test_descriptor.dart' as d;
@@ -15,10 +12,10 @@ import 'package:sass/src/embedded/utils.dart';
1512
import 'embedded_process.dart';
1613
import 'utils.dart';
1714

18-
void main() {
15+
void sharedTests(Future<EmbeddedProcess> runSassEmbedded()) {
1916
late EmbeddedProcess process;
2017
setUp(() async {
21-
process = await EmbeddedProcess.start();
18+
process = await runSassEmbedded();
2219
});
2320

2421
group("emits a protocol error", () {

test/embedded/length_delimited_test.dart renamed to test/embedded/shared/length_delimited.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
@TestOn('vm')
6-
library;
7-
85
import 'dart:async';
96
import 'dart:typed_data';
107

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

16-
void main() {
13+
void sharedTests() {
1714
group("encoder", () {
1815
late Sink<List<int>> sink;
1916
late Stream<List<int>> stream;

test/embedded/protocol_test.dart renamed to test/embedded/shared/protocol.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
@TestOn('vm')
6-
library;
7-
85
import 'package:path/path.dart' as p;
96
import 'package:pub_semver/pub_semver.dart';
107
import 'package:source_maps/source_maps.dart' as source_maps;
@@ -17,10 +14,10 @@ import 'package:sass/src/embedded/utils.dart';
1714
import 'embedded_process.dart';
1815
import 'utils.dart';
1916

20-
void main() {
17+
void sharedTests(Future<EmbeddedProcess> runSassEmbedded()) {
2118
late EmbeddedProcess process;
2219
setUp(() async {
23-
process = await EmbeddedProcess.start();
20+
process = await runSassEmbedded();
2421
});
2522

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

456453
var failure = await getCompileFailure(process);
457-
expect(failure.message, startsWith("Cannot open file: "));
458-
expect(failure.message.replaceFirst("Cannot open file: ", "").trim(),
454+
expect(
455+
failure.message,
456+
anyOf(startsWith("Cannot open file: "),
457+
startsWith("no such file or directory: ")));
458+
expect(
459+
failure.message
460+
.replaceFirst("Cannot open file: ", "")
461+
.replaceFirst("no such file or directory: ", "")
462+
.trim(),
459463
equalsPath(d.path('test.scss')));
460464
expect(failure.span.text, equals(''));
461465
expect(failure.span.context, equals(''));
File renamed without changes.

0 commit comments

Comments
 (0)