Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main into feature.color-4 #1965

Merged
merged 14 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ name: CI
defaults:
run: {shell: bash}

env:
# TODO(jathak): Update this to Node 18 once unit tests are fixed.
NODE_VERSION: 14

on:
push: {branches: [main, feature.*]}
pull_request:
Expand All @@ -18,8 +14,9 @@ jobs:

steps:
- uses: actions/checkout@v3
# TODO(jathak): Update this to 'lts/*' (the latest lts version) once unit tests are fixed.
- uses: actions/setup-node@v3
with: {node-version: "${{ env.NODE_VERSION }}"}
with: {node-version: 14}
- uses: dart-lang/setup-dart@v1
with: {sdk: stable}
- run: npm install
Expand All @@ -32,7 +29,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with: {node-version: "${{ env.NODE_VERSION }}"}
with: {node-version: 'lts/*'}
- run: npm install
- run: npm run lint

Expand All @@ -43,7 +40,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with: {node-version: "${{ env.NODE_VERSION }}"}
with: {node-version: 'lts/*'}
- run: npm install
- run: npm run lint-spec

Expand All @@ -59,7 +56,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with: {node-version: "${{ env.NODE_VERSION }}"}
with: {node-version: 'lts/*'}
- run: npm install

- uses: ./.github/util/dart-sass
Expand All @@ -69,10 +66,7 @@ jobs:

- name: Run specs
run: npm run sass-spec -- --dart dart-sass

# The versions should be kept up-to-date with the latest LTS Node releases.
# They next need to be rotated October 2021. See
# https://github.com/nodejs/Release.

js_api_dart_sass:
name: "JS API | Pure JS | Node ${{ matrix.node_version }} | ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
Expand All @@ -82,13 +76,15 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node_version: [18]
node_version: ['lts/*']
# Only test LTS versions on Ubuntu
include:
- os: ubuntu-latest
node_version: 14
node_version: lts/-1
- os: ubuntu-latest
node_version: 16
node_version: lts/-2
- os: ubuntu-latest
node_version: lts/-3

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -136,9 +132,6 @@ jobs:
--sassSassRepo dart-sass/build/language
env: {CHROME_EXECUTABLE: chrome}

# The versions should be kept up-to-date with the latest LTS Node releases.
# They next need to be rotated October 2021. See
# https://github.com/nodejs/Release.
js_api_sass_embedded:
name: "JS API | Embedded | Node ${{ matrix.node_version }} | ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
Expand All @@ -148,13 +141,15 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node_version: [18]
node_version: ['lts/*']
# Only test LTS versions on Ubuntu
include:
- os: ubuntu-latest
node_version: 14
node_version: lts/-1
- os: ubuntu-latest
node_version: lts/-2
- os: ubuntu-latest
node_version: 16
node_version: lts/-3

steps:
- uses: actions/checkout@v3
Expand Down
140 changes: 140 additions & 0 deletions js-api-spec/compiler.node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright 2024 Google Inc. 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.

import type {AsyncCompiler, Compiler, CompileResult, Importer} from 'sass';
import {initAsyncCompiler, initCompiler} from 'sass';

import {
asyncImporters,
functions,
getLogger,
getTriggeredImporter,
importers,
} from './compiler.test';
import {sandbox} from './sandbox';
import {URL} from './utils';

describe('Compiler', () => {
let compiler: Compiler;

beforeEach(() => {
compiler = initCompiler();
});

afterEach(() => {
compiler.dispose();
});

describe('compile', () => {
it('performs complete compilations', () =>
sandbox(dir => {
const logger = getLogger();
dir.write({'input.scss': '@import "bar"; .fn {value: foo(bar)}'});
const result = compiler.compile(dir('input.scss'), {
importers,
functions,
logger,
});
expect(result.css).toEqualIgnoringWhitespace(
'.import {value: bar;} .fn {value: "bar";}'
);
expect(logger.debug).toHaveBeenCalledTimes(1);
}));

it('performs compilations in callbacks', () =>
sandbox(dir => {
dir.write({'input-nested.scss': 'x {y: z}'});
const nestedImporter: Importer = {
canonicalize: () => new URL('foo:bar'),
load: () => ({
contents: compiler.compile(dir('input-nested.scss')).css,
syntax: 'scss',
}),
};
dir.write({'input.scss': '@import "nested"; a {b: c}'});
const result = compiler.compile(dir('input.scss'), {
importers: [nestedImporter],
});
expect(result.css).toEqualIgnoringWhitespace('x {y: z;} a {b: c;}');
}));

it('throws after being disposed', () =>
sandbox(dir => {
dir.write({'input.scss': '$a: b; c {d: $a}'});
compiler.dispose();
expect(() => compiler.compile(dir('input.scss'))).toThrowError();
}));
});
});

describe('AsyncCompiler', () => {
let compiler: AsyncCompiler;

beforeEach(async () => {
compiler = await initAsyncCompiler();
});

afterEach(async () => {
await compiler.dispose();
});

describe('compileAsync', () => {
it(
'handles multiple concurrent compilations',
() =>
sandbox(async dir => {
const runs = 1000; // Number of concurrent compilations to run
const logger = getLogger();
const compilations = Array(runs)
.fill(0)
.map((_, i) => {
const filename = `input-${i}.scss`;
dir.write({
[filename]: `@import "${i}"; .fn {value: foo(${i})}`,
});
return compiler.compileAsync(dir(filename), {
importers: asyncImporters,
functions,
logger,
});
});
Array.from(await Promise.all(compilations))
.map((result: CompileResult) => result.css)
.forEach((result, i) => {
expect(result).toEqualIgnoringWhitespace(
`.import {value: ${i};} .fn {value: "${i}";}`
);
});
expect(logger.debug).toHaveBeenCalledTimes(runs);
}),
40_000 // Increase timeout for slow CI
);

it('throws after being disposed', () =>
sandbox(async dir => {
dir.write({'input.scss': '$a: b; c {d: $a}'});
await compiler.dispose();
expect(() => compiler.compileAsync(dir('input.scss'))).toThrowError();
}));

it('waits for compilations to finish before disposing', () =>
sandbox(async dir => {
let completed = false;
dir.write({'input.scss': '@import "slow"'});
const {importer, triggerComplete} = getTriggeredImporter(
() => (completed = true)
);
const compilation = compiler.compileAsync(dir('input.scss'), {
importers: [importer],
});
const disposalPromise = compiler.dispose();
expect(completed).toBeFalse();
triggerComplete();

await disposalPromise;
expect(completed).toBeTrue();
await expectAsync(compilation).toBeResolved();
}));
});
});
Loading
Loading