Skip to content

Commit 0c64213

Browse files
committed
Tests, bump version
1 parent e3e3d13 commit 0c64213

File tree

8 files changed

+101
-4
lines changed

8 files changed

+101
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ npm-debug.log*
1818
yarn-debug.log*
1919
yarn-error.log*
2020
lerna-debug.log*
21+
*.cpuprofile

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](https://semver.org/).
55

6+
## 1.0.2 2021-05-07
7+
* Performance improvement (parser)
8+
69
## 1.0.0 2021-05-05
710
* Stable Release
811
* Bug fixes

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rollup-plugin-glsl-optimize",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Import GLSL source files as strings. Pre-processed, validated and optimized with Khronos Group SPIRV-Tools. Supports glslify.",
55
"homepage": "https://github.com/docd27/rollup-plugin-glsl-optimize#readme",
66
"keywords": [

test/tests/glslify.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
import {npmCommand} from '../../src/lib/tools.js';
2+
import {glslifyInit, glslifyProcessSource} from '../../src/lib/glslify.js';
23
import {rollup} from 'rollup';
34
import {assert} from 'chai';
45
import * as fsSync from 'fs';
56

7+
const consoleOrig = global.console;
8+
let outBuf;
9+
function mockConsoleError() {
10+
outBuf = '';
11+
global.console = {...consoleOrig};
12+
global.console.error = (...args) => {
13+
outBuf += `${args.map(String).join(' ')}\n`;
14+
};
15+
global.console.warn = global.console.error;
16+
}
17+
function unMockConsoleError() {
18+
global.console = consoleOrig;
19+
return outBuf;
20+
}
21+
622
async function glslifyUninstall() {
723
await npmCommand(['uninstall', 'glslify', 'glsl-noise']);
824
assert.isFalse(fsSync.existsSync('node_modules/glslify'), 'glslify failed to uninstall');
@@ -13,7 +29,6 @@ async function glslifyInstall() {
1329
assert.isTrue(fsSync.existsSync('node_modules/glslify'), 'glslify failed to install');
1430
}
1531

16-
1732
/**
1833
* @param {typeof import('../../src/index.js').default} glslOptimize
1934
*/
@@ -33,6 +48,14 @@ export function glslifyTests(glslOptimize) {
3348
this.timeout(30000);
3449
before('install glslify', glslifyInstall);
3550
after('uninstall glslify', glslifyUninstall);
51+
it('should warn about glslify failing to find includes', async function() {
52+
await glslifyInit();
53+
mockConsoleError();
54+
await glslifyProcessSource('does/not/exist/', '', {basedir: '/does/not/exist'}, (message) => {
55+
throw new Error(message);
56+
});
57+
assert.include(unMockConsoleError(), 'glslify may fail to find includes');
58+
});
3659
it('should pass with glslify enabled but unused', async function() {
3760
const bundle = await rollup({
3861
input: 'test/fixtures/basic.js',

test/tests/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {installTests} from './install.js';
77
import {utilTests} from './util.js';
88
import {parserTests} from './parser.js';
99
import {preambleTests} from './preamble.js';
10+
import {minifyTests} from './minify.js';
1011
import {glslifyTests} from './glslify.js';
1112
import {shaderTests} from './shader.js';
1213

@@ -29,6 +30,7 @@ export function runTests(glslOptimize) {
2930
utilTests();
3031
parserTests();
3132
preambleTests();
33+
minifyTests();
3234
shaderTests(glslOptimize);
3335
glslifyTests(glslOptimize);
3436
}

test/tests/minify.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {assert} from 'chai';
2+
import {compressShader} from '../../src/lib/minify.js';
3+
4+
export function minifyTests() {
5+
describe('Minify', function() {
6+
describe('#compressShader()', function() {
7+
it('should minify basic', function() {
8+
const input = `AAA;\n` +
9+
`\n` +
10+
`BBB;\n`;
11+
const expected = `AAA;BBB;`;
12+
assert.strictEqual(compressShader(input), expected);
13+
});
14+
it('should minify preprocessor directives', function() {
15+
const input = `AAA;\n\n` +
16+
`#C\n` +
17+
`BBB;\n\n`;
18+
const expected = `AAA;\n#C\nBBB;`;
19+
assert.strictEqual(compressShader(input), expected);
20+
});
21+
});
22+
});
23+
}

test/tests/shader.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,54 @@
11
import {rollup} from 'rollup';
22
import {assert} from 'chai';
3+
import {glslProcessSource} from '../../src/lib/glslProcess.js';
34

5+
const consoleOrig = global.console;
6+
let outBuf;
7+
function mockConsoleError() {
8+
outBuf = '';
9+
global.console = {...consoleOrig};
10+
global.console.error = (...args) => {
11+
outBuf += `${args.map(String).join(' ')}\n`;
12+
};
13+
global.console.warn = global.console.error;
14+
}
15+
function unMockConsoleError() {
16+
global.console = consoleOrig;
17+
return outBuf;
18+
}
419

520
/** @param {typeof import('../../src/index.js').default} glslOptimize */
621
export function shaderTests(glslOptimize) {
22+
describe('glslProcessSource', function() {
23+
it('should warn about failing to find includes', async function() {
24+
const input = `#version 300 es
25+
precision mediump float;
26+
27+
in vec3 vpos;
28+
out vec4 outColor;
29+
30+
void main() {
31+
outColor = vec4(vpos, 1.0);
32+
}`;
33+
34+
mockConsoleError();
35+
await glslProcessSource('does/not/exist', input, 'frag');
36+
assert.include(unMockConsoleError(), 'may fail to find includes');
37+
});
38+
it('should throw an error for GLSL < 300 es', async function() {
39+
const input = `#version 100
40+
precision mediump float;
41+
42+
in vec3 vpos;
43+
out vec4 outColor;
44+
45+
void main() {
46+
outColor = vec4(vpos, 1.0);
47+
}`;
48+
49+
await assert.isRejected(glslProcessSource('.', input, 'frag'), /shaders version/);
50+
});
51+
});
752
describe('Shader', function() {
853
it('should throw an error with a .glsl lacking a shader stage file extension', async function() {
954
assert.isRejected(rollup({

0 commit comments

Comments
 (0)