Skip to content

Commit

Permalink
fixed and issue with loading the correct test renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Feb 5, 2022
1 parent e47a9e1 commit ae58858
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/vue-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run test-unit
- run: npm test -- --headless
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function viteNightwatchPlugin(options = {}) {
defaultRenderPage = 'src/react_renderer.html';
break;
default:
defaultRenderPage = 'src/react_renderer.html';
defaultRenderPage = 'src/vue_renderer.html';
}

defaultRenderPage = path.join('node_modules', 'vite-plugin-nightwatch', defaultRenderPage);
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"test": "nightwatch --env vue",
"test-unit": "mocha test/unit",
"test-react": "nightwatch --env react"
},
"keywords": [
Expand All @@ -27,6 +28,8 @@
"@vitejs/plugin-react": "^1.1.4",
"@vitejs/plugin-vue": "^2.1.0",
"chromedriver": "^97.0.4",
"mocha": "^9.2.0",
"mockery": "^2.1.0",
"nightwatch": "^2.0.5",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/lib/vite.config-vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
plugins: [
vue(),
nightwatchPlugin({
renderPage: './src/test_renderer.html'
renderPage: './src/vue_renderer.html'
})
]
})
109 changes: 109 additions & 0 deletions test/unit/testPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const assert = require('assert');
const fs = require('fs');

describe('Vite Nightwatch plugin basic tests', function() {

it('test plugin config with defaults', function(done) {
fs.readFile = (filename, encoding, callback) => {
assert.ok(filename.endsWith('vite-plugin-nightwatch/src/vue_renderer.html'));
callback(null, '');
};

const Plugin = require('../../index.js');
const server = Plugin();

server.configureServer({
transformIndexHtml(url, data) {
assert.strictEqual(url, 'http://localhost');

done();

return Promise.resolve('')
},

middlewares: {
use(url, fn) {
assert.strictEqual(url, '/test_render/');

const req = {
url: 'http://localhost'
};
const res = {};


fn(req, res);
}
}
});
});

it('test plugin config with componentType=react', function(done) {
fs.readFile = (filename, encoding, callback) => {
assert.ok(filename.endsWith('vite-plugin-nightwatch/src/react_renderer.html'));
callback(null, '');
};

const Plugin = require('../../index.js');
const server = Plugin({
componentType: 'react'
});

server.configureServer({
transformIndexHtml(url, data) {
assert.strictEqual(url, 'http://localhost');

done();

return Promise.resolve('')
},

middlewares: {
use(url, fn) {
assert.strictEqual(url, '/test_render/');

const req = {
url: 'http://localhost'
};
const res = {};


fn(req, res);
}
}
});
});

it('test plugin config with custom renderPage', function(done) {
fs.readFile = (filename, encoding, callback) => {
assert.strictEqual(filename, 'custom_renderer.html');
callback(null, '');
};

const Plugin = require('../../index.js');
const server = Plugin({
renderPage: 'custom_renderer.html'
});

server.configureServer({
transformIndexHtml(url, data) {
done();

return Promise.resolve('')
},

middlewares: {
use(url, fn) {
assert.strictEqual(url, '/test_render/');

const req = {
url: 'http://localhost'
};
const res = {};


fn(req, res);
}
}
});
});
});

0 comments on commit ae58858

Please sign in to comment.