Skip to content

Commit

Permalink
Update test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 28, 2021
1 parent 4b8514a commit 26ced57
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 155 deletions.
81 changes: 39 additions & 42 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,43 @@
"**/*.ts"
],
"rules": {
"indent": [2, "tab", { "SwitchCase": 1 }],
"semi": [2, "always"],
"keyword-spacing": [2, { "before": true, "after": true }],
"space-before-blocks": [2, "always"],
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"no-cond-assign": 0,
"no-unused-vars": 2,
"object-shorthand": [2, "always"],
"no-const-assign": 2,
"no-class-assign": 2,
"no-this-before-super": 2,
"no-var": 2,
"no-unreachable": 2,
"valid-typeof": 2,
"quote-props": [2, "as-needed"],
"one-var": [2, "never"],
"prefer-arrow-callback": 2,
"prefer-const": [2, { "destructuring": "all" }],
"arrow-spacing": 2
},
"env": {
"es6": true,
"browser": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:import/errors", "plugin:import/warnings"],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"settings": {
"import/ignore": [0, ["\\.path.js$"]]
},
"overrides": [
{
"files": ["./test/**"],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
}
}
]
"indent": [ 2, "tab", { "SwitchCase": 1 } ],
"semi": [ 2, "always" ],
"keyword-spacing": [ 2, { "before": true, "after": true } ],
"space-before-blocks": [ 2, "always" ],
"no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ],
"no-cond-assign": 0,
"no-unused-vars": 2,
"object-shorthand": [ 2, "always" ],
"no-const-assign": 2,
"no-class-assign": 2,
"no-this-before-super": 2,
"no-var": 2,
"no-unreachable": 2,
"valid-typeof": 2,
"quote-props": [ 2, "as-needed" ],
"one-var": [ 2, "never" ],
"prefer-arrow-callback": 2,
"prefer-const": [ 2, { "destructuring": "all" } ],
"arrow-spacing": 2
},
"env": {
"es6": true,
"browser": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"settings": {
"import/ignore": [ 0, [
"\\.path.js$"
] ]
}
}
2 changes: 1 addition & 1 deletion .nycrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"exclude": ["*commonjsHelpers.js", "test"],
"exclude": ["test"],
"extension": [".ts", ""]
}
3 changes: 0 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Place your settings in this file to overwrite default and user settings.
{
"typescript.format.insertSpaceBeforeFunctionParenthesis": true,
"typescript.format.insertSpaceAfterConstructor": true,
Expand Down
10 changes: 7 additions & 3 deletions browser/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ export function relative(from: string, to: string) {
}

export function resolve(...paths: string[]) {
let resolvedParts = paths.shift()!.split(/[/\\]/);
const firstPathSegment = paths.shift();
if (!firstPathSegment) {
return '/';
}
let resolvedParts = firstPathSegment.split(/[/\\]/);

paths.forEach(path => {
for (const path of paths) {
if (isAbsolute(path)) {
resolvedParts = path.split(/[/\\]/);
} else {
Expand All @@ -75,7 +79,7 @@ export function resolve(...paths: string[]) {

resolvedParts.push.apply(resolvedParts, parts);
}
});
}

return resolvedParts.join('/');
}
31 changes: 14 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,34 @@
},
"scripts": {
"build": "shx rm -rf dist && git rev-parse HEAD > .commithash && rollup -c && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x dist/bin/rollup",
"build:test": "shx rm -rf dist && rollup -c --configTest && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x dist/bin/rollup",
"build:cjs": "shx rm -rf dist && rollup -c --configTest && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x dist/bin/rollup",
"build:bootstrap": "dist/bin/rollup -c && shx cp src/rollup/types.d.ts dist/rollup.d.ts && shx chmod a+x dist/bin/rollup",
"ci:lint": "npm run lint:nofix",
"ci:test": "npm run build:test && npm run build:bootstrap && npm run test:all",
"ci:test:only": "npm run build:test && npm run build:bootstrap && npm run test:only",
"ci:coverage": "npm run build:test && nyc --reporter lcovonly mocha && codecov",
"ci:test": "npm run build:cjs && npm run build:bootstrap && npm run test:all",
"ci:test:only": "npm run build:cjs && npm run build:bootstrap && npm run test:only",
"ci:coverage": "npm run build:cjs && nyc --reporter lcovonly mocha && codecov",
"lint": "npm run lint:ts -- --fix && npm run lint:js -- --fix && npm run lint:markdown",
"lint:nofix": "npm run lint:ts && npm run lint:js && npm run lint:markdown",
"lint:ts": "tslint --project .",
"lint:js": "eslint test/test.js test/*/index.js test/utils.js test/**/_config.js",
"lint:markdown": "markdownlint --config markdownlint.json docs/**/*.md",
"perf": "npm run build:test && node --expose-gc scripts/perf.js",
"perf": "npm run build:cjs && node --expose-gc scripts/perf.js",
"perf:debug": "node --inspect-brk scripts/perf-debug.js",
"perf:init": "node scripts/perf-init.js",
"prepare": "npm run build",
"prepublishOnly": "npm ci && npm run lint:nofix && npm run security && npm run build:bootstrap && npm run test:all",
"pretest": "npm run build:test",
"pretest:browser": "npm run build",
"pretest:coverage": "npm run build:test && shx rm -rf coverage/*",
"pretest:typescript": "shx rm -rf test/typescript/dist && shx cp -r dist test/typescript/",
"security": "# npm audit # deactivated until there is a solution for the lodash issue",
"test": "npm run test:all",
"test:all": "npm run test:only && npm run test:typescript && npm run test:leak && npm run test:package",
"test:coverage": "nyc --reporter html mocha test/test.js",
"security": "npm audit",
"test": "npm run build && npm run test:all",
"test:cjs": "npm run build:cjs && npm run test:only",
"test:quick": "mocha -b test/test.js",
"test:all": "npm run test:only && npm run test:browser && npm run test:typescript && npm run test:leak && npm run test:package",
"test:coverage": "npm run build:cjs && shx rm -rf coverage/* && nyc --reporter html mocha test/test.js",
"test:coverage:browser": "npm run build && shx rm -rf coverage/* && nyc mocha test/browser/index.js",
"test:leak": "node --expose-gc test/leak/index.js",
"test:package": "node scripts/test-package.js",
"test:only": "mocha test/test.js",
"test:quick": "mocha -b test/test.js",
"test:typescript": "tsc --noEmit -p test/typescript && tsc --noEmit",
"test:browser": "mocha test/browser/index.mjs",
"test:browser:quick": "mocha -b test/browser/index.mjs",
"test:typescript": "shx rm -rf test/typescript/dist && shx cp -r dist test/typescript/ && tsc --noEmit -p test/typescript && tsc --noEmit",
"test:browser": "mocha test/browser/index.js",
"watch": "rollup -cw"
},
"repository": "rollup/rollup",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default command => {
treeshake,
strictDeprecations: true,
output: [
{ file: 'dist/rollup.browser.js', format: 'umd', name: 'rollup', banner },
{ file: 'dist/rollup.browser.js', format: 'umd', name: 'rollup', banner, sourcemap: true },
{ file: 'dist/es/rollup.browser.js', format: 'es', banner }
]
};
Expand Down
6 changes: 3 additions & 3 deletions src/utils/relativeId.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { basename, extname, isAbsolute, relative } from './path';
import { basename, extname, isAbsolute, relative, resolve } from './path';
import { sanitizeFileName } from './sanitizeFileName';

export function getAliasName(id: string) {
Expand All @@ -7,8 +7,8 @@ export function getAliasName(id: string) {
}

export default function relativeId(id: string) {
if (typeof process === 'undefined' || !isAbsolute(id)) return id;
return relative(process.cwd(), id);
if (!isAbsolute(id)) return id;
return relative(resolve(), id);
}

export function isPlainPathFragment(name: string) {
Expand Down
76 changes: 76 additions & 0 deletions test/browser/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const fixturify = require('fixturify');
const { basename, resolve } = require('path');
const { rollup } = require('../../dist/rollup.browser.js');
const { assertFilesAreEqual, runTestSuiteWithSamples, compareError } = require('../utils.js');

runTestSuiteWithSamples('browser', resolve(__dirname, 'samples'), (dir, config) => {
(config.skip ? it.skip : config.solo ? it.only : it)(
basename(dir) + ': ' + config.description,
async () => {
let bundle;
try {
bundle = await rollup({
input: 'main',
onwarn: warning => {
if (!(config.expectedWarnings && config.expectedWarnings.indexOf(warning.code) >= 0)) {
throw new Error(
`Unexpected warnings (${warning.code}): ${warning.message}\n` +
'If you expect warnings, list their codes in config.expectedWarnings'
);
}
},
strictDeprecations: true,
...config.options
});
} catch (error) {
if (config.error) {
compareError(error, config.error);
return;
} else {
throw error;
}
}
if (config.error) {
throw new Error('Expected an error while rolling up');
}
let output;
try {
({ output } = await bundle.generate({
exports: 'auto',
format: 'es',
...(config.options || {}).output
}));
} catch (error) {
if (config.generateError) {
compareError(error, config.generateError);
return;
} else {
throw error;
}
}
if (config.generateError) {
throw new Error('Expected an error while generating output');
}
assertOutputMatches(output, dir);
}
);
});

function assertOutputMatches(output, dir) {
const actual = {};
for (const file of output) {
const filePath = file.fileName.split('/');
const fileName = filePath.pop();
let currentDir = actual;
for (const pathElement of filePath) {
if (!currentDir[pathElement]) {
currentDir[pathElement] = {};
}
currentDir = currentDir[pathElement] = currentDir[pathElement] || {};
}
currentDir[fileName] = file.source || file.code;
}
fixturify.writeSync(resolve(dir, '_actual'), actual);
const expected = fixturify.readSync(resolve(dir, '_expected'));
assertFilesAreEqual(actual, expected);
}
83 changes: 0 additions & 83 deletions test/browser/index.mjs

This file was deleted.

1 change: 0 additions & 1 deletion test/browser/samples/basic/_config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { loader } = require('../../../utils.js');

module.exports = {
show: true,
description: 'bundles files for the browser',
options: {
plugins: loader({
Expand Down

0 comments on commit 26ced57

Please sign in to comment.