test(mocks): run only the services that emit, and widen the UNC exception
The replay covers the files that call webout(), so a shared module added to the tree is skipped instead of failing with a require error, while the _webout assertion still reads every file - a service that writes its own body cannot slip past the filter. A UNC prefix is legal after any character that is not a word character, a colon or another separator, so a path inside a tag or after a comma keeps its prefix instead of reading as a doubled separator.
This commit is contained in:
1 parent
88cc68e2f9
commit
676cdf6fdd
1 file changed
+26
-7
@@ -33,13 +33,25 @@ function walk(dir) {
|
||||
)
|
||||
}
|
||||
|
||||
/** Every captured service, in a stable order. weboutGuard is not a service. */
|
||||
/** Every file under the tree, in a stable order. weboutGuard is not a service. */
|
||||
function serviceFiles() {
|
||||
return walk(SERVICES)
|
||||
.filter((file) => file.endsWith('.js') && !file.endsWith('weboutGuard.js'))
|
||||
.sort()
|
||||
}
|
||||
|
||||
/**
|
||||
* The services this harness can run: the ones that emit through webout(). A
|
||||
* shared module that only exports helpers is skipped here, and the test below
|
||||
* still reads every file, so a service that assigns the body itself cannot
|
||||
* hide behind the filter.
|
||||
*/
|
||||
function emittingFiles() {
|
||||
return serviceFiles().filter((file) =>
|
||||
/(^|[^.\w])webout\s*\(/.test(fs.readFileSync(file, 'utf8'))
|
||||
)
|
||||
}
|
||||
|
||||
/** Runs a service the way the SASjs Server runtime does, keeping its members. */
|
||||
function runService(file) {
|
||||
const members = {}
|
||||
@@ -81,9 +93,9 @@ function leaves(node, prefix, out) {
|
||||
function faultsIn(value) {
|
||||
const faults = []
|
||||
|
||||
// A backslash run is legitimate only as a UNC prefix (`\\server\share`), at
|
||||
// the start of a value or of a quoted path. Anywhere else two consecutive
|
||||
// separators mean one was written twice, and a run of three never happens.
|
||||
// A backslash run of two is legitimate only as a UNC prefix
|
||||
// (`\\server\share`); the data has no other use for two separators in a row,
|
||||
// and a run of three never happens.
|
||||
for (
|
||||
let at = value.indexOf('\\\\');
|
||||
at >= 0;
|
||||
@@ -92,8 +104,10 @@ function faultsIn(value) {
|
||||
let end = at + 2
|
||||
while (value.charCodeAt(end) === BACKSLASH) end++
|
||||
const before = at === 0 ? '' : value[at - 1]
|
||||
const uncPrefix =
|
||||
end - at === 2 && (before === '' || /[\s"'(<=]/.test(before))
|
||||
// a path keeps its prefix wherever a value can put one - after a tag, a
|
||||
// quote, a comma, a space - but not straight after a word character, a
|
||||
// colon (C:\\ is the drive fault) or another separator
|
||||
const uncPrefix = end - at === 2 && !/[\w:\\]/.test(before)
|
||||
if (!uncPrefix) {
|
||||
faults.push('doubled separator')
|
||||
break
|
||||
@@ -147,7 +161,7 @@ function faultsIn(value) {
|
||||
|
||||
test('every sas9 service emits its separators once', () => {
|
||||
const failures = []
|
||||
for (const file of serviceFiles()) {
|
||||
for (const file of emittingFiles()) {
|
||||
const rel = path.relative(SERVICES, file)
|
||||
for (const [key, value] of leaves(runService(file), '', [])) {
|
||||
if (typeof value !== 'string') continue
|
||||
@@ -180,6 +194,11 @@ test('a UNC path is not a doubled separator', () => {
|
||||
[]
|
||||
)
|
||||
assert.deepStrictEqual(faultsIn("LIBURI: '\\\\fileserver\\share'"), [])
|
||||
assert.deepStrictEqual(
|
||||
faultsIn('<Path>\\fileserver\share\mpe.sas7bdat</Path>'),
|
||||
[]
|
||||
)
|
||||
assert.deepStrictEqual(faultsIn('a,\\fileserver\share'), [])
|
||||
// a separator written twice where one belongs is still a fault
|
||||
assert.deepStrictEqual(faultsIn('C:\\\\DataController\\\\mpe.sas7bdat'), [
|
||||
'doubled separator'
|
||||
|
||||
Reference in new issue
Block a user