Skip to content

Commit

Permalink
Merge pull request #1729 from yunnysunny/feat/old-node
Browse files Browse the repository at this point in the history
Re-enable the test for old Node
  • Loading branch information
titanism authored Jun 8, 2022
2 parents 4f043a8 + 18896ec commit 26c72d0
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
- name: Install Dependencies On Old Node ${{ matrix.node-version }}
if: ${{ matrix.test-on-old-node == '1' }}
run: yarn install --ignore-optional --ignore-scripts
run: node ci/remove-deps-4-old-node.js && yarn install --ignore-scripts
- name: Install Dependencies On Node ${{ matrix.node-version }}
if: ${{ matrix.test-on-old-node != '1' }}
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged && yarn test
yarn test
28 changes: 28 additions & 0 deletions ci/remove-deps-4-old-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require('fs');
const path = require('path');
const package = require('../package.json');

const UNSUPPORT_DEPS_4_OLD = new Set([
'@commitlint/cli',
'@commitlint/config-conventional',
'eslint',
'eslint-config-xo-lass',
'eslint-plugin-compat',
'eslint-plugin-node',
'husky',
'lint-staged',
'remark-cli',
'remark-preset-github',
'xo'
]);

for (const item in package.devDependencies) {
if (UNSUPPORT_DEPS_4_OLD.has(item)) {
package.devDependencies[item] = undefined;
}
}

fs.writeFileSync(
path.join(__dirname, '../package.json'),
JSON.stringify(package, null, 2)
);
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"@babel/plugin-transform-runtime": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/runtime": "^7.18.3",
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@commitlint/cli": "^16.3.0",
"@commitlint/config-conventional": "^16.2.4",
"Base64": "^1.1.0",
"babelify": "^10.0.0",
"basic-auth-connect": "^1.0.0",
Expand All @@ -55,7 +55,7 @@
"express-session": "^1.17.3",
"fixpack": "^4.0.0",
"get-port": "4.2.0",
"husky": "^8.0.1",
"husky": "^7.0.4",
"lint-staged": "^12.5.0",
"marked": "^2.0.0",
"mocha": "6.2.2",
Expand Down
33 changes: 27 additions & 6 deletions test/node/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function getFullPath(filename) {
}

const fullPath = path.join(__dirname, '../../', filename);
return fullPath.charAt(0).toLowerCase() + fullPath.slice(1);
return fullPath;
}

describe('Multipart', () => {
Expand Down Expand Up @@ -104,7 +104,14 @@ describe('Multipart', () => {
assert.ok(Boolean(error), 'Request should have failed.');
error.code.should.equal('ENOENT');
error.message.should.containEql('ENOENT');
error.path.should.equal(getFullPath('foo'));
if (IS_WINDOWS) {
error.path.toLowerCase().should.equal(
getFullPath('foo').toLowerCase()
);
} else {
error.path.should.equal(getFullPath('foo'));
}

done();
});
});
Expand All @@ -118,7 +125,14 @@ describe('Multipart', () => {
(res) => assert.fail('It should not allow this'),
(err) => {
err.code.should.equal('ENOENT');
err.path.should.equal(getFullPath('does-not-exist.txt'));
if (IS_WINDOWS) {
err.path.toLowerCase().should.equal(
getFullPath('does-not-exist.txt').toLowerCase()
);
} else {
err.path.should.equal(getFullPath('does-not-exist.txt'));
}

}
);
});
Expand Down Expand Up @@ -190,9 +204,16 @@ describe('Multipart', () => {
.end((error, res) => {
assert.ok(Boolean(error), 'Request should have failed.');
error.code.should.equal('ENOENT');
error.path.should.equal(
getFullPath('test/node/fixtures/non-existent-file.ext')
);
if (IS_WINDOWS) {
error.path.toLowerCase().should.equal(
getFullPath('test/node/fixtures/non-existent-file.ext').toLowerCase()
);
} else {
error.path.should.equal(
getFullPath('test/node/fixtures/non-existent-file.ext')
);
}

done();
});
});
Expand Down
6 changes: 5 additions & 1 deletion test/node/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict';
const assert = require('assert');
const utils = require('../../lib/utils');
const utils =
process.env.OLD_NODE_TEST === '1'
// eslint-disable-next-line node/no-missing-require
? require('../../../utils')
: require('../../lib/utils');

describe('utils.type(str)', () => {
it('should return the mime type', () => {
Expand Down
Loading

0 comments on commit 26c72d0

Please sign in to comment.