diff --git a/package.json b/package.json index fa3aebb7c..e58681eae 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ }, "devDependencies": { "coveralls": "^3.0.7", + "eol": "^0.9.1", "eslint": "^6.6.0", "fs-extra": "^8.1.0", "istanbul": "^0.4.2", @@ -83,6 +84,8 @@ "read-yaml": "^1.0.0", "rimraf": "^2.5.2", "sass-spec": "https://github.com/sass/sass-spec.git#7c3750d", - "unique-temp-dir": "^1.0.0" + "through2": "^3.0.1", + "unique-temp-dir": "^1.0.0", + "vinyl-fs": "^3.0.3" } } diff --git a/scripts/pretest.js b/scripts/pretest.js index 43f7f05cd..63f69ce77 100644 --- a/scripts/pretest.js +++ b/scripts/pretest.js @@ -1,68 +1,64 @@ const { - createReadStream, existsSync: exists, mkdirSync, - copy, - outputFile -} = require('fs-extra'); +} = require('fs'); const { join, - basename, - dirname + normalize } = require('path'); -const { promisify } = require('util'); -const glob = promisify(require('glob')); +const { Readable } = require('stream'); +const eol = require('eol'); const { archiveFromStream } = require('node-hrx'); -const srcSpecPath = require('sass-spec').dirname.replace(/\\/g, '/'); -const destSpecPath = 'test/fixtures/sass-spec'; +const through2 = require('through2'); +const vfs = require('vinyl-fs'); +const Vinyl = require('vinyl'); + +const srcSpecPath = normalize(require('sass-spec').dirname); +const destSpecPath = normalize('test/fixtures/sass-spec'); if(!exists(destSpecPath)) { mkdirSync(destSpecPath); } -copy(srcSpecPath, destSpecPath) - .then(async () => { - const hrxFiles = await glob(srcSpecPath+'/**/*.hrx'); - const archives = await Promise.all( - hrxFiles.map(async file => { - const archive = await archiveFromStream(createReadStream(file, 'utf8')); +const extractHrxDir = function(dir) { + let files = []; + for (const entryName of dir) { + const entry = dir.contents[entryName]; + if(entry.isDirectory()) { + files = files.concat(extractHrxDir(entry)); + } else { + files.push(entry); + } + } - return { - archive, - archivePath: file - }; - }) - ); - const extractHrxDir = function(dir) { - let files = []; - for (const entryName of dir) { - const entry = dir.contents[entryName]; - if(entry.isDirectory()) { - files = files.concat(extractHrxDir(entry)); - } else { - files.push(entry); - } - } + return files; +}; - return files; - }; +vfs.src( + join(srcSpecPath, '**/*').replace(/\\/g, '/').replace(/^\w:/, '') +).pipe( + through2.obj(async function(file, enc, callback) { + if(file.extname === '.hrx') { + const stream = Readable.from(eol.lf(file.contents.toString())); + const archive = await archiveFromStream(stream); + const archivedFiles = extractHrxDir(archive); - const extrFiles = archives.reduce( - (prevExtr, {archive, archivePath}) => { - const fileObjs = extractHrxDir(archive).map(innerFile => { - const path = join( - dirname(archivePath), - basename(archivePath, '.hrx'), - innerFile.path - ).replace(srcSpecPath, destSpecPath); + for (const fileObj of archivedFiles) { + const path = join(file.path.slice(0,-4), fileObj.path); - return { path, body: innerFile.body }; + const extFile = new Vinyl({ + cwd: file.cwd, + base: file.base, + path, + contents: Buffer.from(fileObj.body) }); - return prevExtr.concat(fileObjs); - }, - [] - ); + this.push(extFile); + } - return Promise.all(extrFiles.map(({path, body}) => outputFile(path, body))); - }); + callback(); + } else { + callback(null, file); + } + }) +).pipe(vfs.dest(destSpecPath)); diff --git a/test/spec.js b/test/spec.js index e8dac9365..3e7ef55d6 100644 --- a/test/spec.js +++ b/test/spec.js @@ -10,7 +10,7 @@ var assert = require('assert'), readYaml = require('read-yaml'), mergeWith = require('lodash/mergeWith'), glob = require('glob'), - specPath = join(__dirname, 'fixtures/sass-spec/spec'), + specPath = 'test/fixtures/sass-spec/spec', impl = function(entry) { return entry.match(/(sass\/)?libsass.*/g) !== null; }, version = 3.6; @@ -118,8 +118,8 @@ var runTest = function(inputCssPath, options) { if (test.shouldFail) { const expectedError = read(test.errorPath, 'utf8').replace(/DEPRECATION WARNING:[\s\w().\-"]+\n\n/,''); assert.equal( - error.formatted.toString().split('\n')[0], - expectedError.toString().split('\n')[0], + (error.formatted.toString().split('\n')[0]).replace(/\r$/g, ''), + (expectedError.toString().split('\n')[0]).replace(/\r$/g, ''), 'Should Error.\nOptions' + JSON.stringify(test.options) ); } else if (exists(test.expectedPath)) {