Skip to content

Commit

Permalink
ci: 解决测试工程访问 gl 环境不一致 (#2369)
Browse files Browse the repository at this point in the history
* chore: 解决测试工程访问 gl 不一致

* test: 统一 mock gl 实例

* chore: mock console in js dom

* deps: headless gl to v8

* chore: mock console error

* chore: remove mock console

* chore: system dependencies up to date for use headless-gl in ubuntu

* chore: run coverage test in ubuntu

* ci: merge to ci actions
  • Loading branch information
lvisei committed Mar 29, 2024
1 parent 623a47a commit ef4d3dd
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 143 deletions.
53 changes: 49 additions & 4 deletions .github/workflows/test.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,51 @@
name: Test
name: CI

on:
push:
branches: [master]
pull_request:
branches:
- '**'

permissions:
contents: read # to fetch code (actions/checkout)

concurrency:
group: '${{ github.workflow }} - ${{ github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

# TODO: prepare-install CI To caching dependencies to speed up workflows
- name: Install dependencies
run: yarn

- name: Check
run: |
yarn check-deps
#TODO: turn on after format fixd
# yarn check-format

- name: Lint
run: yarn lint:ts

#TODO: turn on after fixd
# - name: Stylelint
# run: yarn lint:css

unit-test:
# TODO: change to ubuntu-latest, gl CONTEXT.getExtension('STACKGL_resize_drawingbuffer') must in macos-latest
runs-on: macos-latest
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
Expand All @@ -19,11 +56,19 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: Install system dependencies
# install system dependencies up to date for use headless-gl in ubuntu
# see https://github.com/stackgl/headless-gl#how-can-i-use-headless-gl-with-a-continuous-integration-service
run: sudo apt-get install -y build-essential libgl1-mesa-dri libglapi-mesa
libglew-dev libglu1-mesa-dev libosmesa6
libxi-dev mesa-utils pkg-config

- name: Install dependencies
run: yarn

- name: Coverage Test
run: yarn test-cover
# use xvfb-run run in ubuntu
run: xvfb-run yarn test-cover

- name: Upload test coverage
uses: coverallsapp/github-action@master
Expand Down
32 changes: 0 additions & 32 deletions .github/workflows/lint.yml

This file was deleted.

2 changes: 1 addition & 1 deletion __tests__/unit/preset/environment.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(window as any).URL.createObjectURL = function () {};
(window as any).URL.createObjectURL = jest.fn;
6 changes: 2 additions & 4 deletions packages/renderer/__tests__/regl/attribute.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { gl } from '@antv/l7-core';
import { createContext } from '@antv/l7-test-utils';
import { glContext } from '@antv/l7-test-utils';
import regl from 'regl';
import quad from '../../../core/src/shaders/post-processing/quad.glsl';
import ReglAttribute from '../../src/regl/ReglAttribute';
Expand All @@ -8,12 +8,10 @@ import ReglModel from '../../src/regl/ReglModel';
import checkPixels from './utils/check-pixels';

describe('ReglAttribute', () => {
let context;
let reGL: regl.Regl;

beforeEach(() => {
context = createContext(1, 1);
reGL = regl(context);
reGL = regl(glContext);
});

it('should initialize without `size`', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/renderer/__tests__/regl/elements.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gl } from '@antv/l7-core';
import { createContext } from '@antv/l7-test-utils';

import { glContext } from '@antv/l7-test-utils';
import regl from 'regl';
import quad from '../../../core/src/shaders/post-processing/quad.glsl';
import ReglAttribute from '../../src/regl/ReglAttribute';
Expand All @@ -10,12 +10,10 @@ import ReglModel from '../../src/regl/ReglModel';
import checkPixels from './utils/check-pixels';

describe('ReglElements', () => {
let context;
let reGL: regl.Regl;

beforeEach(() => {
context = createContext(1, 1);
reGL = regl(context);
reGL = regl(glContext);
});

it('should initialize correctly', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/renderer/__tests__/regl/framebuffer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gl } from '@antv/l7-core';
import { createContext } from '@antv/l7-test-utils';

import { glContext } from '@antv/l7-test-utils';
import regl from 'regl';
import quad from '../../../core/src/shaders/post-processing/quad.glsl';
import ReglAttribute from '../../src/regl/ReglAttribute';
Expand All @@ -13,12 +13,10 @@ import ReglTexture2D from '../../src/regl/ReglTexture2D';
import checkPixels from './utils/check-pixels';

describe('ReglFramebuffer', () => {
let context;
let reGL: regl.Regl;

beforeEach(() => {
context = createContext(1, 1);
reGL = regl(context);
reGL = regl(glContext);
});

it('should initialize correctly', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/renderer/__tests__/regl/model.draw.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gl } from '@antv/l7-core';
import { createContext } from '@antv/l7-test-utils';

import { glContext } from '@antv/l7-test-utils';
import regl from 'regl';
import quad from '../../../core/src/shaders/post-processing/quad.glsl';
import ReglAttribute from '../../src/regl/ReglAttribute';
Expand All @@ -10,12 +10,10 @@ import checkPixels from './utils/check-pixels';
import globalDefaultprecision from './utils/default-precision';

describe('Initialization for ReglModel', () => {
let context;
let reGL: regl.Regl;

beforeEach(() => {
context = createContext(1, 1);
reGL = regl(context);
reGL = regl(glContext);
});

it('should draw a red quad', () => {
Expand Down
7 changes: 2 additions & 5 deletions packages/renderer/__tests__/regl/model.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { createContext } from '@antv/l7-test-utils';

import { glContext } from '@antv/l7-test-utils';
import regl from 'regl';
import ReglModel from '../../src/regl/ReglModel';

describe('ReglModel', () => {
let context;
let reGL: regl.Regl;

beforeEach(() => {
context = createContext(1, 1);
reGL = regl(context);
reGL = regl(glContext);
});

it('should generate model with empty uniforms correctly', () => {
Expand Down
7 changes: 2 additions & 5 deletions packages/renderer/__tests__/regl/model.uniform.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { createContext } from '@antv/l7-test-utils';

import { glContext } from '@antv/l7-test-utils';
import regl from 'regl';
import ReglFramebuffer from '../../src/regl/ReglFramebuffer';
import ReglModel from '../../src/regl/ReglModel';
import ReglTexture2D from '../../src/regl/ReglTexture2D';

describe('uniforms in ReglModel', () => {
let gl;
let reGL: regl.Regl;

beforeEach(() => {
gl = createContext(1, 1);
reGL = regl(gl);
reGL = regl(glContext);
});

it('should generate model with empty uniforms correctly', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/renderer/__tests__/regl/renderer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gl } from '@antv/l7-core';
import { createContext } from '@antv/l7-test-utils';

import { glContext } from '@antv/l7-test-utils';
import regl from 'regl';
import copy from '../../../core/src/shaders/post-processing/copy.glsl';
import quad from '../../../core/src/shaders/post-processing/quad.glsl';
Expand All @@ -11,13 +11,11 @@ import checkPixels from './utils/check-pixels';
import globalDefaultprecision from './utils/default-precision';

describe('ReglRendererService', () => {
let context;
let reGL: regl.Regl;
const rendererService = new ReglRendererService();

beforeEach(() => {
context = createContext(1, 1);
reGL = regl(context);
reGL = regl(glContext);
// @ts-ignore
rendererService.gl = reGL;
});
Expand Down
6 changes: 2 additions & 4 deletions packages/renderer/__tests__/regl/texture.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gl } from '@antv/l7-core';
import { createContext } from '@antv/l7-test-utils';

import { glContext } from '@antv/l7-test-utils';
import regl from 'regl';
import copy from '../../../core/src/shaders/post-processing/copy.glsl';
import quad from '../../../core/src/shaders/post-processing/quad.glsl';
Expand All @@ -12,12 +12,10 @@ import checkPixels from './utils/check-pixels';
import globalDefaultprecision from './utils/default-precision';

describe('ReglTexture', () => {
let context;
let reGL: regl.Regl;

beforeEach(() => {
context = createContext(1, 1);
reGL = regl(context);
reGL = regl(glContext);
});

it('should initialize with `data`', () => {
Expand Down
21 changes: 0 additions & 21 deletions packages/renderer/__tests__/regl/utils/create-context.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"regl": "1.6.1"
},
"devDependencies": {
"@antv/l7-test-utils": "2.21.1",
"gl": "^6.0.2"
"@antv/l7-test-utils": "2.21.1"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"clean": "rimraf dist es lib"
},
"dependencies": {
"gl": "^6.0.2",
"gl": "^8.0.2",
"regl": "1.6.1"
},
"peerDependencies": {
Expand All @@ -39,7 +39,7 @@
"@antv/l7-scene": "^2.21.0"
},
"devDependencies": {
"@types/gl": "^6.0.4"
"@types/gl": "^6.0.5"
},
"publishConfig": {
"access": "public",
Expand Down
15 changes: 0 additions & 15 deletions packages/test-utils/src/check-pixels.ts

This file was deleted.

23 changes: 0 additions & 23 deletions packages/test-utils/src/create-context.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/test-utils/src/default-precision.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/test-utils/src/gl-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import gl from 'gl';

/** Test context */
export const glContext = gl(1, 1, { preserveDrawingBuffer: true });
4 changes: 2 additions & 2 deletions packages/test-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as createContext } from './create-context';
export * from './test-scene';
export { glContext } from './gl-context';
export { TestScene } from './test-scene';
Loading

0 comments on commit ef4d3dd

Please sign in to comment.