-
Notifications
You must be signed in to change notification settings - Fork 220
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
chore(test): set up integration testing #461
Merged
+9,648
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
test/integration/scenarios/basic-setup/basic-setup.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import ScenarioUtils from '../../utils/ScenarioUtils'; | ||
|
||
const path = require('path'); | ||
|
||
describe('A basic karma-webpack setup', () => { | ||
let scenario; | ||
|
||
const TEST_PATH = path.resolve(__dirname, './index.scenario.js'); | ||
|
||
const config = { | ||
frameworks: ['webpack', 'mocha'], | ||
files: [{ pattern: TEST_PATH }], | ||
preprocessors: { [TEST_PATH]: ['webpack'] }, | ||
webpack: {}, | ||
browsers: ['ChromeHeadless'], | ||
// Explicitly turn off reporters so the simulated test results are not confused with the actual results. | ||
reporters: [], | ||
port: 2389, | ||
logLevel: 'OFF', | ||
singleRun: true, | ||
}; | ||
|
||
const plugins = ['karma-webpack', 'karma-chrome-launcher', 'karma-mocha']; | ||
|
||
beforeAll((done) => { | ||
ScenarioUtils.run(config, plugins) | ||
.then((res) => { | ||
scenario = res; | ||
done(); | ||
}) | ||
.catch((err) => { | ||
jest.fail('Karma run has failed with an error', err); | ||
}); | ||
}); | ||
|
||
it('should have three successful test runs', () => { | ||
expect(scenario.success).toBe(3); | ||
}); | ||
|
||
it('should have one failed test run', () => { | ||
expect(scenario.failed).toBe(1); | ||
}); | ||
|
||
it('should complete with no errors', () => { | ||
expect(scenario.error).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('./js-source-example.js'); | ||
require('./js-test-example.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const AdvancedMath = { | ||
add, | ||
}; | ||
|
||
function add(a, b) { | ||
return a + b; | ||
} | ||
|
||
export default AdvancedMath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import AdvancedMath from './js-source-example'; | ||
|
||
const assert = require('assert'); | ||
|
||
describe('test one example', () => { | ||
it('an example passing test', () => { | ||
assert.strictEqual(1, 1); | ||
}); | ||
}); | ||
|
||
describe('test two example', () => { | ||
it('an example failing test', () => { | ||
assert.strictEqual(1, 0); | ||
}); | ||
}); | ||
|
||
describe('bundled js content', () => { | ||
it('should be able to bundle js content', () => { | ||
assert.strictEqual(!!AdvancedMath.add, true); | ||
}); | ||
it('should be able to interpret bundled js content', () => { | ||
assert.strictEqual(AdvancedMath.add(1, 1), 2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
process.env.CHROME_BIN = require('puppeteer').executablePath(); | ||
const karmaChromeLauncher = require('karma-chrome-launcher'); | ||
const karmaMocha = require('karma-mocha'); | ||
const { Server } = require('karma'); | ||
|
||
const karmaWebpack = require('../../../lib/index'); | ||
|
||
const PLUGINS = { | ||
'karma-webpack': karmaWebpack, | ||
'karma-mocha': karmaMocha, | ||
'karma-chrome-launcher': karmaChromeLauncher, | ||
}; | ||
|
||
function getPlugin(plugin) { | ||
if (PLUGINS[plugin]) return PLUGINS[plugin]; | ||
throw new Error( | ||
`Tried to load an unknown plugin [${plugin}] while running a karma scenario.` | ||
); | ||
} | ||
|
||
process.on('message', ({ config, plugins }) => { | ||
if (config.plugins) { | ||
throw new Error(` | ||
Error: please specify plugins as the second argument of ScenarioUtils.run. \n | ||
available plugins: [${Object.keys(PLUGINS).join(',')}]} | ||
`); | ||
} | ||
|
||
const karmaConfiguration = config; | ||
karmaConfiguration.plugins = plugins.map(getPlugin); | ||
const server = new Server(karmaConfiguration); | ||
// This will run once when the karma server completes running tests. | ||
server.on('run_complete', (browsers, results) => process.send(results)); | ||
server.start(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { fork } = require('child_process'); | ||
const path = require('path'); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
const karma = require('karma'); | ||
|
||
const ScenarioUtils = { run }; | ||
|
||
/** | ||
* This allows you to run a karma with a given configuration and list of plugins, | ||
* on completion you will be returned a karma results object. | ||
* | ||
* @param {karma.ConfigOptions} config - The base karma configuration. | ||
* @param {Array<String>} plugins - A list of plugins to be required | ||
* @returns {Promise<karma.TestResults>} | ||
*/ | ||
function run(config, plugins) { | ||
return new Promise((resolve, reject) => { | ||
fork(path.resolve(`${__dirname}/KarmaWorker.js`)) | ||
.on('close', reject) | ||
.on('error', reject) | ||
.on('message', resolve) | ||
.send({ config, plugins }); | ||
}); | ||
} | ||
|
||
export default ScenarioUtils; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be the reason, why you don't see logs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added right at the end to keep the tests from being noisy, unrelated to the issue I was having. I'll try to get a repro up sometime today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this made me realize that I totally missed pushing one of my files though 🤦♂️