mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Update mocha tests, use bdd style assertions consistently
This commit is contained in:
+2
-2
@@ -81,8 +81,8 @@
|
||||
"styleguide:build": "vue-styleguidist build",
|
||||
"test": "yarn run test-mocha && yarn run test-qunit",
|
||||
"test-watch": "yarn run test-mocha --no-single-run",
|
||||
"test-qunit": "karma start karma/karma.config.qunit.js",
|
||||
"test-mocha": "karma start karma/karma.config.mocha.js",
|
||||
"test-qunit": "karma start test/karma/karma.config.qunit.js",
|
||||
"test-mocha": "karma start test/karma/karma.config.mocha.js",
|
||||
"eslint": "eslint -c .eslintrc.js src --ext .js,.vue"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import DatatypesMappingJson from "qunit/test-data/json/datatypes.mapping.json";
|
||||
import DatatypesJson from "qunit/test-data/json/datatypes.json";
|
||||
// TODO: Swap these awful relative paths to an alias
|
||||
import DatatypesMappingJson from "../../../test/qunit/test-data/json/datatypes.mapping.json";
|
||||
import DatatypesJson from "../../../test/qunit/test-data/json/datatypes.json";
|
||||
import { DatatypesMapperModel } from "./model.js";
|
||||
|
||||
export const typesAndMappingResponse = {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import MockAdapter from "axios-mock-adapter";
|
||||
import axios from "axios";
|
||||
import DatasetCollectionDialog from "./DatasetCollectionDialog.vue";
|
||||
import { setupTestGalaxy } from "qunit/test-app";
|
||||
import SelectionDialog from "./SelectionDialog.vue";
|
||||
import { setupTestGalaxy } from "../../../test/qunit/test-app";
|
||||
import SelectionDialog from "./SelectionDialog.vue";
|
||||
|
||||
import { shallowMount, createLocalVue } from "@vue/test-utils";
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import axios from "axios";
|
||||
import WorkflowDialog from "./WorkflowDialog.vue";
|
||||
import { __RewireAPI__ as rewire } from "components/Workflow/services";
|
||||
import SelectionDialog from "./SelectionDialog.vue";
|
||||
import { setupTestGalaxy } from "qunit/test-app";
|
||||
import { setupTestGalaxy } from "../../../test/qunit/test-app";
|
||||
|
||||
import { shallowMount, createLocalVue } from "@vue/test-utils";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import MockAdapter from "axios-mock-adapter";
|
||||
import axios from "axios";
|
||||
import UploadModal from "./UploadModal.vue";
|
||||
import { setupTestGalaxy } from "qunit/test-app";
|
||||
import { setupTestGalaxy } from "../../../test/qunit/test-app";
|
||||
|
||||
import { shallowMount, createLocalVue } from "@vue/test-utils";
|
||||
|
||||
|
||||
@@ -4,30 +4,32 @@
|
||||
|
||||
const webpackConfigFunc = require("./webpack.config.unittest");
|
||||
|
||||
module.exports = config => {
|
||||
|
||||
module.exports = (config) => {
|
||||
// Karma does not execute the webpack config function by default
|
||||
const webpackConfig = webpackConfigFunc({}, {
|
||||
mode: "testing"
|
||||
});
|
||||
const webpackConfig = webpackConfigFunc(
|
||||
{},
|
||||
{
|
||||
mode: "testing",
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
basePath: "../src",
|
||||
basePath: "../../src",
|
||||
browsers: ["ChromeHeadlessNoSandbox"],
|
||||
client: {
|
||||
captureConsole: true
|
||||
captureConsole: true,
|
||||
},
|
||||
failOnEmptyTestSuite: false,
|
||||
singleRun: true,
|
||||
webpack: webpackConfig,
|
||||
webpackMiddleware: {
|
||||
noInfo: true
|
||||
noInfo: true,
|
||||
},
|
||||
customLaunchers: {
|
||||
ChromeHeadlessNoSandbox: {
|
||||
base: "ChromeHeadless",
|
||||
flags: ["--no-sandbox"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
flags: ["--no-sandbox"],
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -14,30 +14,31 @@ const defaultFiles = [
|
||||
// component/module tests
|
||||
"**/*.test.js",
|
||||
// pre-existing rules definition tests
|
||||
"**/mocha/tests/*_tests.js"
|
||||
"../test/mocha/tests/rules_tests.js",
|
||||
];
|
||||
|
||||
function getTestFiles() {
|
||||
// check for user-supplied list
|
||||
let userPatterns = getUserTestGlobs();
|
||||
let patterns = userPatterns.length ? userPatterns : defaultFiles;
|
||||
return patterns.map(pattern => ({ pattern, watched: true}));
|
||||
const userPatterns = getUserTestGlobs();
|
||||
const patterns = userPatterns.length ? userPatterns : defaultFiles;
|
||||
return patterns.map((pattern) => ({ pattern, watched: true }));
|
||||
}
|
||||
|
||||
// command line arg "watch-only" can be a list of file globs
|
||||
// for karma to watch
|
||||
function getUserTestGlobs() {
|
||||
let userGlobs = process.argv.find(s => s.startsWith("watch-only"));
|
||||
const userGlobs = process.argv.find((s) => s.startsWith("watch-only"));
|
||||
return userGlobs ? processUserGlobs(userGlobs) : [];
|
||||
}
|
||||
|
||||
// split command line arg into an array
|
||||
function processUserGlobs(val) {
|
||||
let result = [];
|
||||
let fileListString = val.split("=")[1];
|
||||
const fileListString = val.split("=")[1];
|
||||
if (fileListString) {
|
||||
result = fileListString.split(",")
|
||||
.map(s => s.trim())
|
||||
result = fileListString
|
||||
.split(",")
|
||||
.map((s) => s.trim())
|
||||
.map(checkGlobPrefix);
|
||||
}
|
||||
return result;
|
||||
@@ -49,23 +50,19 @@ function checkGlobPrefix(glob) {
|
||||
}
|
||||
|
||||
module.exports = function (config) {
|
||||
|
||||
const baseConfig = baseKarmaConfig(config);
|
||||
|
||||
let files = [
|
||||
"../../node_modules/@babel/polyfill/dist/polyfill.js",
|
||||
...getTestFiles()
|
||||
];
|
||||
const files = ["../node_modules/@babel/polyfill/dist/polyfill.js", ...getTestFiles()];
|
||||
|
||||
let settings = Object.assign({}, baseConfig, {
|
||||
const settings = Object.assign({}, baseConfig, {
|
||||
files,
|
||||
preprocessors: {
|
||||
"**/*.js": ["webpack"]
|
||||
"**/*.js": ["webpack"],
|
||||
},
|
||||
exclude: ["**/qunit/*"],
|
||||
reporters: ["mocha"],
|
||||
frameworks: ["mocha", "chai"]
|
||||
frameworks: ["mocha", "chai"],
|
||||
});
|
||||
|
||||
config.set(settings);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,29 +11,23 @@
|
||||
|
||||
const baseKarmaConfig = require("./karma.config.base");
|
||||
|
||||
const testFiles = [
|
||||
"../../node_modules/@babel/polyfill/dist/polyfill.js",
|
||||
"qunit/test.js"
|
||||
];
|
||||
const testFiles = ["node_modules/@babel/polyfill/dist/polyfill.js", "../qunit/test.js"];
|
||||
|
||||
const assets = [
|
||||
"qunit/assets/*.css"
|
||||
];
|
||||
const assets = ["../qunit/assets/*.css"];
|
||||
|
||||
let preprocessors = testFiles.reduce((result, path) => {
|
||||
const preprocessors = testFiles.reduce((result, path) => {
|
||||
result[path] = ["webpack"];
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
module.exports = function (config) {
|
||||
|
||||
const baseConfig = baseKarmaConfig(config);
|
||||
|
||||
let settings = Object.assign({}, baseConfig, {
|
||||
const settings = Object.assign({}, baseConfig, {
|
||||
files: testFiles.concat(assets),
|
||||
preprocessors: preprocessors,
|
||||
frameworks: ["polyfill", "qunit"],
|
||||
singleRun: true
|
||||
singleRun: true,
|
||||
});
|
||||
|
||||
config.set(settings);
|
||||
|
||||
@@ -4,47 +4,43 @@
|
||||
* TODO: Replace these tests with like... actual unit tests.
|
||||
*/
|
||||
|
||||
const baseConfig = require("../webpack.config");
|
||||
const baseConfig = require("../../webpack.config");
|
||||
|
||||
module.exports = (env, argv) => {
|
||||
|
||||
// load base config
|
||||
let wpConfig = baseConfig(env, argv);
|
||||
const wpConfig = baseConfig(env, argv);
|
||||
wpConfig.mode = "production";
|
||||
wpConfig.entry = () => ({});
|
||||
|
||||
const switchPlugin = (reMatcher, replacement) => {
|
||||
|
||||
let scrubLoader = (obj) =>
|
||||
(typeof obj == "string" && obj.match(reMatcher))
|
||||
? Object.assign({}, replacement)
|
||||
: obj
|
||||
const scrubLoader = (obj) =>
|
||||
typeof obj == "string" && obj.match(reMatcher) ? Object.assign({}, replacement) : obj;
|
||||
|
||||
return (rule) => {
|
||||
if (rule.use && rule.use.length) {
|
||||
rule.use = rule.use.map(scrubLoader);
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Remove MiniCssExtractPlugin loader references
|
||||
// replace mini-css-extract plugin with basic style loader
|
||||
// Honestly I'm not clear on why we process css at all for unit tests
|
||||
const scrubLoaderRules = (module) => {
|
||||
let rePluginMatch = /mini-css-extract-plugin/;
|
||||
let styleLoader = { loader: "style-loader" };
|
||||
let processor = switchPlugin(rePluginMatch, styleLoader);
|
||||
const rePluginMatch = /mini-css-extract-plugin/;
|
||||
const styleLoader = { loader: "style-loader" };
|
||||
const processor = switchPlugin(rePluginMatch, styleLoader);
|
||||
module.rules = module.rules.map(processor);
|
||||
}
|
||||
};
|
||||
|
||||
// Remove mini-css-extract loader references
|
||||
scrubLoaderRules(wpConfig.module);
|
||||
|
||||
// remove MiniCSSExtract Plugin
|
||||
wpConfig.plugins = wpConfig.plugins.filter(p => {
|
||||
wpConfig.plugins = wpConfig.plugins.filter((p) => {
|
||||
return p.constructor.name != "MiniCssExtractPlugin";
|
||||
});
|
||||
|
||||
return wpConfig;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,35 +4,33 @@
|
||||
*/
|
||||
|
||||
const merge = require("webpack-merge");
|
||||
const baseConfig = require("../webpack.config");
|
||||
const baseConfig = require("../../webpack.config");
|
||||
|
||||
module.exports = (env, argv) => {
|
||||
|
||||
const wpConfig = baseConfig(env, argv);
|
||||
wpConfig.mode = "development";
|
||||
wpConfig.entry = () => ({});
|
||||
|
||||
// Don't need any assets for unit testing
|
||||
let ignoreAssetLoaders = {
|
||||
rules:[
|
||||
const ignoreAssetLoaders = {
|
||||
rules: [
|
||||
{
|
||||
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?.*$|$)/,
|
||||
loader: "ignore-loader"
|
||||
loader: "ignore-loader",
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
loader: "ignore-loader"
|
||||
loader: "ignore-loader",
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
loader: "ignore-loader"
|
||||
}
|
||||
]
|
||||
loader: "ignore-loader",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
wpConfig.module = merge.smart(wpConfig.module, ignoreAssetLoaders);
|
||||
|
||||
|
||||
// Using babel-plugin-rewire to handle dependency mocking since webpack 4
|
||||
// exports immutable bindings for ES modules but we still need a way to
|
||||
// overwrite dependencies during unit-testing.
|
||||
@@ -41,13 +39,13 @@ module.exports = (env, argv) => {
|
||||
// node-modules, without our exceptions to support IE as in parent webpack
|
||||
// config.
|
||||
|
||||
wpConfig.module.rules = wpConfig.module.rules.map(rule => {
|
||||
wpConfig.module.rules = wpConfig.module.rules.map((rule) => {
|
||||
if (rule.loader == "babel-loader") {
|
||||
rule.exclude = [/(node_modules\/)/]
|
||||
rule.exclude = [/(node_modules\/)/];
|
||||
rule.options.plugins.push("rewire");
|
||||
}
|
||||
return rule;
|
||||
});
|
||||
|
||||
return wpConfig;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1 +1 @@
|
||||
../../../../../lib/galaxy_test/base/data/rules_dsl_spec.yml
|
||||
../../../../lib/galaxy_test/base/data/rules_dsl_spec.yml
|
||||
@@ -1,11 +1,8 @@
|
||||
import chai from "chai";
|
||||
import RuleDefs from "mvc/rules/rule-definitions";
|
||||
import SPEC_TEST_CASES from "json-loader!yaml-loader!./rules_dsl_spec.yml";
|
||||
|
||||
const RULES = RuleDefs.RULES;
|
||||
|
||||
function applyRules(rules, data, sources) {
|
||||
let columns = [];
|
||||
const columns = [];
|
||||
if (data[0]) {
|
||||
for (const index in data[0]) {
|
||||
columns.push("new");
|
||||
@@ -20,9 +17,9 @@ function itShouldConform(specTestCase, i) {
|
||||
doc = " - " + specTestCase.doc;
|
||||
}
|
||||
it("should pass conformance test case " + i + " (from rules_dsl_spec.yml)" + doc, function () {
|
||||
chai.assert.property(specTestCase, "rules");
|
||||
expect(specTestCase).to.have.property("rules");
|
||||
if (specTestCase.initial) {
|
||||
chai.assert.property(specTestCase, "final");
|
||||
expect(specTestCase).to.have.property("final");
|
||||
|
||||
const rules = specTestCase.rules;
|
||||
const initial = specTestCase.initial;
|
||||
@@ -31,12 +28,12 @@ function itShouldConform(specTestCase, i) {
|
||||
const final = applyRules(rules, initial.data, initial.sources);
|
||||
const finalData = final.data;
|
||||
const finalSources = final.sources;
|
||||
chai.assert.deepEqual(finalData, expectedFinal.data);
|
||||
expect(finalData).to.deep.equal(expectedFinal.data);
|
||||
if (expectedFinal.sources !== undefined) {
|
||||
chai.assert.deepEqual(finalSources, expectedFinal.sources);
|
||||
expect(finalSources).to.deep.equal(expectedFinal.sources);
|
||||
}
|
||||
} else {
|
||||
chai.assert(specTestCase.error);
|
||||
expect(specTestCase.error).to.be.true;
|
||||
// TODO: test these...
|
||||
}
|
||||
});
|
||||
|
||||
@@ -9,8 +9,8 @@ import sinon from "sinon";
|
||||
import Backbone from "backbone";
|
||||
import { setGalaxyInstance } from "app";
|
||||
import { getAppRoot } from "onload";
|
||||
import galaxyOptions from "qunit/test-data/bootstrapped";
|
||||
import serverdata from "qunit/test-data/fakeserver";
|
||||
import galaxyOptions from "./test-data/bootstrapped";
|
||||
import serverdata from "./test-data/fakeserver";
|
||||
import "./assets/base.css";
|
||||
|
||||
export function setupTestGalaxy(galaxyOptions_ = null) {
|
||||
|
||||
Reference in New Issue
Block a user