From 0a60c48711c649b267723f03d9e03661974f0900 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Tue, 4 Jan 2022 17:51:13 +0100 Subject: [PATCH] add integration tests to validate piping to the CLI --- integrations/execute.js | 13 +++++++++---- .../tailwindcss-cli/tests/integration.test.js | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/integrations/execute.js b/integrations/execute.js index bab80b4bad25..7b0f7e799c23 100644 --- a/integrations/execute.js +++ b/integrations/execute.js @@ -21,9 +21,14 @@ module.exports = function $(command, options = {}) { let abortController = new AbortController() let cwd = resolveToolRoot() - let args = command.split(' ') - command = args.shift() - command = command === 'node' ? command : path.resolve(cwd, 'node_modules', '.bin', command) + let args = options.shell + ? [command] + : (() => { + let args = command.split(' ') + command = args.shift() + command = command === 'node' ? command : path.resolve(cwd, 'node_modules', '.bin', command) + return [command, args] + })() let stdoutMessages = [] let stderrMessages = [] @@ -55,7 +60,7 @@ module.exports = function $(command, options = {}) { }, 200) let runningProcess = new Promise((resolve, reject) => { - let child = spawn(command, args, { + let child = spawn(...args, { ...options, env: { ...process.env, diff --git a/integrations/tailwindcss-cli/tests/integration.test.js b/integrations/tailwindcss-cli/tests/integration.test.js index 1992c9cd503d..066417de0635 100644 --- a/integrations/tailwindcss-cli/tests/integration.test.js +++ b/integrations/tailwindcss-cli/tests/integration.test.js @@ -27,6 +27,23 @@ describe('static build', () => { ) }) + it('should be possible to pipe in data', async () => { + await writeInputFile('index.html', html`
`) + + await $('cat ./src/index.css | node ../../lib/cli.js -i - -o ./dist/main.css', { + shell: true, + env: { NODE_ENV: 'production' }, + }) + + expect(await readOutputFile('main.css')).toIncludeCss( + css` + .font-bold { + font-weight: 700; + } + ` + ) + }) + it('should safelist a list of classes to always include', async () => { await writeInputFile('index.html', html`
`) await writeInputFile(