Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Fix pretest script and test/spec.js
Browse files Browse the repository at this point in the history
Fix the pretest script and the "test/spec.js" test file so that the 
tests pass on Windows machines.
  • Loading branch information
PolyPik committed Mar 20, 2020
1 parent 0bfcab8 commit 1816c88
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 53 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
94 changes: 45 additions & 49 deletions scripts/pretest.js
Original file line number Diff line number Diff line change
@@ -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));
6 changes: 3 additions & 3 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 1816c88

Please sign in to comment.