Skip to content

Commit 5a43255

Browse files
committed
Test with glslify
1 parent 9b1bd81 commit 5a43255

File tree

9 files changed

+53
-14
lines changed

9 files changed

+53
-14
lines changed

fixtures/glsl/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
const fs = require('fs')
21
const glsl = require('glslify')
3-
glsl(fs.readFileSync(__dirname + '/shader.glsl', 'utf8'))
2+
3+
console.log(glsl`
4+
precision mediump float;
5+
#pragma glslify: ones = require(./ones)
6+
void main () {
7+
gl_FragColor = ones();
8+
}
9+
`)

fixtures/glsl/ones.glsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vec4 ones () {
2+
return vec4(1);
3+
}
4+
#pragma glslify: export(ones)

fixtures/glsl/output.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

fixtures/glsl/output.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
precision mediump float;
3+
#define GLSLIFY 1
4+
#define GLSLIFY 1
5+
vec4 ones () {
6+
return vec4(1);
7+
}
8+
9+
void main () {
10+
gl_FragColor = ones();
11+
}
12+
,

fixtures/glsl/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "fixture",
33
"version": "1.0.0",
4+
"scripts": {
5+
"build": "../../node_modules/.bin/webpack webpack.config.js"
6+
},
47
"browserify": {
58
"transform": [
69
"brfs",

fixtures/glsl/webpack.config.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
const path = require('path')
2+
13
module.exports = {
2-
loaders: [
3-
test: /\.(glsl|vert|v|frag|f)$/,
4-
loader: 'ify-loader'
5-
]
4+
entry: './index.js',
5+
output: {
6+
path: __dirname,
7+
filename: 'bundle.js'
8+
},
9+
module: {
10+
rules: [{
11+
test: /\.js/,
12+
use: path.join(__dirname, '..', '..')
13+
}]
14+
}
615
}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function loader (source) {
3737

3838
const name = transform[0]
3939
const opts = transform[1] || {}
40+
opts._flags = opts._flags || []
4041

4142
if (typeof name === 'function') {
4243
return next(null, name(filename, opts))

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"devDependencies": {
2222
"brfs": "^1.4.2",
23+
"from2-string": "^1.1.0",
2324
"glslify": "^6.1.0",
2425
"npm-which": "^2.0.0",
2526
"regl": "^1.3.0",

test.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const path = require('path')
55
const fs = require('fs')
66
const vm = require('vm')
77

8+
/*
89
test('ify-loader', function (t) {
910
const wpack = which.sync('webpack', { cwd: __dirname })
1011
const input = path.join(__dirname, 'fixtures', 'basic', 'index.js')
@@ -88,12 +89,14 @@ test('error handling', function (t) {
8889
t.equal(code, 2, 'exit code was 2')
8990
})
9091
})
92+
*/
9193

9294
test('glsl-transform', function (t) {
9395
const wpack = which.sync('webpack', { cwd: __dirname })
9496
const input = path.join(__dirname, 'fixtures', 'glsl', 'index.js')
9597
const output = path.join(__dirname, 'fixtures', 'glsl', 'bundle.js')
96-
const pkg = path.join(__dirname, 'fixtures', 'glsl', 'output.js')
98+
const config = path.join(__dirname, 'fixtures', 'glsl', 'webpack.config.js')
99+
const fixture = path.join(__dirname, 'fixtures', 'glsl', 'output.txt')
97100

98101
t.plan(1)
99102

@@ -103,9 +106,11 @@ test('glsl-transform', function (t) {
103106

104107
spawn(wpack, [
105108
input,
106-
output,
107-
'--module-bind', 'js=' + __dirname
109+
'--module-bind', 'js=' + __dirname,
110+
'--config',
111+
config
108112
], {
113+
cwd: path.join(__dirname, 'fixtures', 'glsl'),
109114
stdio: ['pipe', 'pipe', 2]
110115
}).once('exit', function () {
111116
const result = fs.readFileSync(output, { encoding: 'utf8' })
@@ -114,9 +119,9 @@ test('glsl-transform', function (t) {
114119

115120
vm.runInNewContext(result, {
116121
console: {
117-
log: function (src) {
118-
const expected = fs.readFileSync(pkg, { encoding: 'utf8' })
119-
t.equal(src, expected, 'processed brfs from package.json')
122+
log: function (shader) {
123+
const expected = fs.readFileSync(fixture, { encoding: 'utf8' })
124+
t.equal(shader + '\n', expected, 'processed brfs from package.json')
120125
},
121126
error: console.error
122127
}

0 commit comments

Comments
 (0)