Require Node.js 12 and move to ESM
This commit is contained in:
parent
4dab5e1fb6
commit
fa16f4ec37
22 changed files with 362 additions and 412 deletions
|
|
@ -1,4 +1,3 @@
|
|||
'use strict';
|
||||
const chalk = require('../source');
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
console.log(`${chalk.hex('#ff6159')('testout')} ${chalk.stderr.hex('#ff6159')('testerr')}`);
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
'use strict';
|
||||
const resolveFrom = require('resolve-from');
|
||||
|
||||
const DEFAULT = {
|
||||
stdout: {
|
||||
level: 3,
|
||||
hasBasic: true,
|
||||
has256: true,
|
||||
has16m: true
|
||||
},
|
||||
stderr: {
|
||||
level: 3,
|
||||
hasBasic: true,
|
||||
has256: true,
|
||||
has16m: true
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = (dir, override) => {
|
||||
require.cache[resolveFrom(dir, 'supports-color')] = {exports: override || DEFAULT};
|
||||
};
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
import test from 'ava';
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
const chalk = require('../source');
|
||||
chalk.level = 3;
|
||||
chalk.stderr.level = 3;
|
||||
|
||||
console.log('TERM:', process.env.TERM || '[none]');
|
||||
console.log('platform:', process.platform || '[unknown]');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import test from 'ava';
|
||||
|
||||
const chalk = require('../source');
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
test('Chalk.constructor should throw an expected error', t => {
|
||||
const expectedError = t.throws(() => {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
import test from 'ava';
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
const chalk = require('../source');
|
||||
chalk.level = 1;
|
||||
|
||||
test('create an isolated context where colors can be disabled (by level)', t => {
|
||||
const instance = new chalk.Instance({level: 0});
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
import path from 'path';
|
||||
import {fileURLToPath} from 'url';
|
||||
import test from 'ava';
|
||||
import execa from 'execa';
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
const chalk = require('../source');
|
||||
chalk.level = 1;
|
||||
|
||||
test('don\'t output colors when manually disabled', t => {
|
||||
const oldLevel = chalk.level;
|
||||
|
|
@ -40,6 +38,6 @@ test('propagate enable/disable changes from child colors', t => {
|
|||
});
|
||||
|
||||
test('disable colors if they are not supported', async t => {
|
||||
const {stdout} = await execa.node(path.join(__dirname, '_fixture'));
|
||||
const {stdout} = await execa.node(fileURLToPath(new URL('./_fixture.js', import.meta.url)));
|
||||
t.is(stdout, 'testout testerr');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
import test from 'ava';
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
// TODO: Do this when ESM supports loader hooks
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname, {
|
||||
stdout: {
|
||||
level: 0,
|
||||
hasBasic: false,
|
||||
has256: false,
|
||||
has16m: false
|
||||
},
|
||||
stderr: {
|
||||
level: 0,
|
||||
hasBasic: false,
|
||||
has256: false,
|
||||
has16m: false
|
||||
}
|
||||
});
|
||||
|
||||
const chalk = require('../source');
|
||||
// require('./_supports-color')(__dirname, {
|
||||
// stdout: {
|
||||
// level: 0,
|
||||
// hasBasic: false,
|
||||
// has256: false,
|
||||
// has16m: false
|
||||
// },
|
||||
// stderr: {
|
||||
// level: 0,
|
||||
// hasBasic: false,
|
||||
// has256: false,
|
||||
// has16m: false
|
||||
// }
|
||||
// });
|
||||
|
||||
test('colors can be forced by using chalk.level', t => {
|
||||
chalk.level = 1;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
/* eslint-disable unicorn/no-hex-escape */
|
||||
import test from 'ava';
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
const chalk = require('../source');
|
||||
chalk.level = 1;
|
||||
|
||||
test('return an empty string for an empty literal', t => {
|
||||
const instance = new chalk.Instance();
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
import test from 'ava';
|
||||
import chalk from '../source/index.js';
|
||||
|
||||
// Spoof supports-color
|
||||
require('./_supports-color')(__dirname);
|
||||
|
||||
const chalk = require('../source');
|
||||
chalk.level = 1;
|
||||
|
||||
test('visible: normal output when level > 0', t => {
|
||||
const instance = new chalk.Instance({level: 3});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue